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



Download 2,61 Mb.
bet106/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   102   103   104   105   106   107   108   109   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

CHALLENGE QUESTION


What is the result of the following code?
>>> values = { 4:4, 8:8, "Q":10, "ACE":11 }
>>> card = ("Q", "Hearts")
>>> print("{ }".format(values[ card[ 0 ] ] ) )

Monday: Creating and Instantiating a Class
All objects in Python are created from classes. The point of OOP is to reuse the same code while giving flexibility to create each object with their own features. Today, we’ll learn the terms and stages of OOP, as well as how to write our first class.
To follow along with the content for today, let’s open up Jupyter Notebook from our
python_bootcamp” folder. Once it’s open, create a new file, and rename it to “Week_07.” Next, make the first cell markdown that has a header saying: “Creating & Instantiating a Class.” We’ll begin working underneath that cell.
What Is an Object?
Look at your surroundings, what do you see? There may be a couch, chair, TV, book, etc., around you right now. In programming, all of these would be referenced as objects. Even people would be referenced as objects. This is because all objects come from a specific blueprint. In Python, those blueprints are known as classes. Let’s take a car, for instance. All cars have similar features and can be built from a template. Each car will generally have wheels, color, make, model, year, VIN number, etc. What classes allow us to do is build out a blueprint that has all these features within it and create different cars from it. This will lessen the code we have to write and give us the ability to give any car we create personal characteristics specific to that object. Figure 7-1 illustrates this concept of creating multiple objects from the same class.

Figure 7-1. Creating three similar cars from the same class blueprint

OOP Stages


There are two stages when using classes. The first stage is the class definition. Like function definitions, this stage is where you write the blueprint to be used when called. The second stage is called instantiation. It is the process of creating an object from the class definition. After an object is instantiated, it is known as an instance. You may have multiple instances from a single class definition. Let’s begin to look at how to define a class and make an instance!

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   102   103   104   105   106   107   108   109   ...   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