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



Download 2,61 Mb.
bet92/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   88   89   90   91   92   93   94   95   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

CHALLENGE QUESTION
This week’s challenge is to write a function that checks if a word is a palindrome. The function should take in a single parameter and return True or False. Try writing the function on paper first, then try programming it!

Monday: Dictionaries
Today, we’ll be learning about a valuable data collection in dictionaries. They store information using keys and are much more efficient than Python lists.
© Connor P. Milliken 2020
C. P. Milliken, Python Projects for Beginners, https://doi.org/10.1007/978-1-4842-5355-7_6
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_06.” Next, make the first cell markdown that has a header saying: “Dictionaries.” We’ll begin working underneath that cell.
What Are Dictionaries?
A dictionary is a collection of unordered data, which is stored in key-value pairs. What is meant by “unordered” is the way it is stored in memory. It is not accessible through an index, rather it is accessed through a key. Lists are known as ordered data collections because each item is assigned a specific location. Dictionaries work like a real-life dictionary, where the key is the word and the values are the definition. Dictionaries are useful for working with large data, mapped data, CSV files, APIs, sending or receiving data, and much more.

Declaring a Dictionary


Like other variables, the name of the variable goes to the left of the equals operator, and on the right is the dictionary. All dictionaries are created by using open and closed curly brackets. In between the curly brackets, we define our key-value pairs. Keys can be declared with ONLY strings or numbers. There’s a colon that separates the key and value. After the colon is the value, and this can be any data type including other data collections or even another dictionary:

# declaring a dictionary variable empty = { } # empty dictionary person = { "name": "John Smith" }
# dictionary with one key/value pair customer = {
"name": "Morty",
"age": 26
} # dictionary with two key/value pairs print(customer)

Go ahead and run the cell. Here we can see that we declare three different dictionaries, an empty one, one that has a single key-value pair, and another that has multiple key value pairs. All key-value pairs must be separated by a comma. We’ll see how to access this data next.
Note You could also use dict( ) to declare an empty dictionary.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   88   89   90   91   92   93   94   95   ...   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