Hey guys, well here are some more of my questions (sorry!! i know, im a pain..) Ive finished "most" of everything in this tutorial. I missed some out because they were too much for
me to understand at the time. will go back to them and come back with more questions:D .
Anyways, could you explaint to me how some of these things work?
#'Inheritance'
class SchoolMember:
'''Represents any school member.'''
def __init__(self, name, age):
self.name = name
self.age = age
print('(Initialized SchoolMember: {0})'.format(self.name))
def tell(self):
'''Tell my details.'''
print('Name:"{0}" Age:"{1}"'.format(self.name, self.age), end=" ")
class Teacher(SchoolMember):
'''Represents a teacher.'''
def __init__(self, name, age, salary):
SchoolMember.__init__(self, name, age)
self.salary = salary
print('(Initialized Teacher: {0})'.format(self.name))
def tell(self):
SchoolMember.tell(self)
print('Salary: "{0:d}"'.format(self.salary))
class Student(SchoolMember):
'''Represents a student.'''
def __init__(self, name, age, marks):
SchoolMember.__init__(self, name, age)
self.marks = marks
print('(Initialized Student: {0})'.format(self.name))
def tell(self):
SchoolMember.tell(self)
print('Marks: "{0:d}"'.format(self.marks))
t = Teacher('Mr. P', 26, 80000)
s = Student('rs', 17, 99)
print() # prints a blank line
members = [t, s]
for member in members:
member.tell() # works for both Teachers and Students
Q1. The last 3 lines on here i do not get.
def reverse(text):
return text[::-1]
def is_palindrome(text):
return text == reverse(text)
something = input('Enter text: ')
if (is_palindrome(something)):
print("Yes, it is a palindrome")
else:
print("No, it is not a palindrome")
Q2. How does "return text[::-1]" here work?
print(line, end='')
Q3. Ive seen (end=''' ) in many places but still do not know what it does
#'pickle'
import pickle
shoplistfile = 'shoplist.data'
shoplist = ['apple', 'mango', 'carrot']
f = open(shoplistfile, 'wb')
pickle.dump(shoplist, f)
f.close()
del shoplist
f = open(shoplistfile, 'rb')
storedlist = pickle.load(f)
print(storedlist)
Q4. Why isn't this working?