diff --git a/Create class and object b/Create class and object new file mode 100644 index 0000000..62dc700 --- /dev/null +++ b/Create class and object @@ -0,0 +1,16 @@ +class Person: + "This is a person class" + age = 10 + + def greet(self): + print('Hello') + + +# Output: 10 +print(Person.age) + +# Output: +print(Person.greet) + +# Output: "This is a person class" +print(Person.__doc__) diff --git a/Creating Class and Objectst b/Creating Class and Objectst new file mode 100644 index 0000000..024ab74 --- /dev/null +++ b/Creating Class and Objectst @@ -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))