Learn Python 3 - Classes Cheatsheet - Codecademy
Learn Python 3 - Classes Cheatsheet - Codecademy
Classes
def __repr__(self):
return self.name
john = Employee('John')
print(john) # John
# Class Instantiation
ferrari = Car()
print(x.class_variable) #I am a Class
Variable!
print(y.class_variable) #I am a Class
Variable!
dog = Animal('Woof')
print(dog.voice) # Output: Woof
Python type() function
a = 1.1
print(type(a)) # <class 'float'>
a = 'b'
print(type(a)) # <class 'str'>
a = None
print(type(a)) # <class 'NoneType'>
Python class
def print_name(self):
print("Hi, I'm " + self.name)
print(dir())
# ['Employee', '__builtins__', '__doc__',
'__file__', '__name__', '__package__',
'new_employee']
print(dir(Employee))
# ['__doc__', '__init__', '__module__',
'print_name']
__main__ in Python
Print Share