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



Download 2,61 Mb.
bet29/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   25   26   27   28   29   30   31   32   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Handling Naming Errors


All programmers make mistakes, so it’s not a problem if you run into errors. It just comes with the job. Let’s look at a common mistake that occurs with variables (no need to write this):
>>> Sport = 'baseball' # capital 'S'
>>> print(sport) # lowercase 'S'
If we try to run this code, we’ll get the following error/output:
NameError: name 'sport' is not defined
This is because the names are completely different. We referenced a variable with a lowercase “s” but declared one with capital “S.” To fix this we would capitalize the “s” in sport within print.

Integer and Float Variables


To store an integer or float in a variable, we give a name to the left of the operator and write a number on the right side. In the next cell, let’s go ahead and write the following code:

num1 = 5 # storing an integer into a variable num2 = 8.4 # storing a float into a variable print(num1, num2) # you can print multiple items using commas

Go ahead and run that cell. Notice the output is 5 and 8.4, even though we print out “num1” and “num2.” We’re printing out the value that is stored in those variables.

Boolean Variables


Remember that booleans are True or False values, so storing them is as simple as typing in one of those two words. Let’s write the following:

# storing a boolean into a variable switch = True print(switch)

Go ahead and run that cell. The resulted output is “True”. Notice that in Jupyter Notebook, the value of True or False will glow green. This is a good indication if we wrote it correctly.

String Variables


Strings are as easy to store as the previous three data types. Just keep in mind that the use of single or double quotes matters. Let’s go ahead and write the following code in a new cell:

# storing strings into a variable name = 'John Smith' fav_number = '9' print(name, fav_number) # will print 9 next to the name

Go ahead and run that. Remember that the string “9” is not the same as the integer 9.
These two data types act differently, even though the output looks similar.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   25   26   27   28   29   30   31   32   ...   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