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
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-classes/cheatsheet 1/4
10/22/24, 9:34 AM Learn Python 3: Classes Cheatsheet | Codecademy
# 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
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-classes/cheatsheet 2/4
10/22/24, 9:34 AM Learn Python 3: Classes Cheatsheet | Codecademy
a = 1.1
print(type(a)) # <class 'float'>
a = 'b'
print(type(a)) # <class 'str'>
a = None
print(type(a)) # <class 'NoneType'>
Python class
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-classes/cheatsheet 3/4
10/22/24, 9:34 AM Learn Python 3: Classes Cheatsheet | Codecademy
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
https://www.codecademy.com/learn/learn-python-3/modules/learn-python3-classes/cheatsheet 4/4