Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Create class and object
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Person:
"This is a person class"
age = 10

def greet(self):
print('Hello')


# Output: 10
print(Person.age)

# Output: <function Person.greet>
print(Person.greet)

# Output: "This is a person class"
print(Person.__doc__)
21 changes: 21 additions & 0 deletions Creating Class and Objectst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Lion:

# class attribute
species = "animal"

# instance attribute
def __init__(self, name, age):
self.name = name
self.age = age

# instantiate the Parrot class
blu = Lion("Blu", 10)
woo = Lion("Woo", 15)

# access the class attributes
print("Blu is a {}".format(blu.__class__.species))
print("Woo is also a {}".format(woo.__class__.species))

# access the instance attributes
print("{} is {} years old".format( blu.name, blu.age))
print("{} is {} years old".format( woo.name, woo.age))