Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet116/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   112   113   114   115   116   117   118   119   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

WEDNESDAY EXERCISES


  1. Animals: Create a class definition of an animal that has a species attribute and both a setter and getter to change or access the attributes value. Create an instance called “lion,” and call the setter method with an argument of “feline.” then print out the species by calling the getter method.

  2. User Input: Create a class Person that takes in a name when instantiated but sets an age to 0. Within the class definition setup, a setter and getter that will ask the user to input their age and set the age attribute to the value input. then output the information in a formatted string as “You are 64 years old.” assuming the user inputs 64 as their age.


today, we were able to learn about methods and how they essentially function within classes. in order to access other methods, we need to use the self parameter. methods give classes extra functionality and are used in almost every class we create. this will give all instances of a given class the same functionalities.
Thursday: Inheritance
Sometimes you’ll create classes that will have similar attributes or methods. Take a Dog and Cat class, for example. Both will have nearly the same code, attributes, and methods.
Rather than writing the same code twice, we use a concept called inheritance.
To follow along with this lesson, let’s continue from our previous notebook file “Week_07” and simply add a markdown cell at the bottom that says, “Inheritance.
What Is Inheritance?
Inheritance is one of the concepts that allow classes to have code reusability within programming. When you have two or more classes that use similar code, you generally want to set up what is called a “superclass.” The two classes that will inherit all the code within the superclass are known as “subclasses.” A great way to think of inheritance is parents and their children. Parents pass down genes to their children, which are inherited and help to define the traits the child will be born with. Inheritance works the same way, where the subclass inherits all the attributes and methods within the superclass. Rather than writing the same attributes and methods twice for two classes, we can inherit a class and only need to write the code once.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   112   113   114   115   116   117   118   119   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish