Python in Education


Obvious Simplicity  |  15



Download 3,73 Mb.
Pdf ko'rish
bet22/37
Sana01.01.2022
Hajmi3,73 Mb.
#303345
1   ...   18   19   20   21   22   23   24   25   ...   37
Bog'liq
Python in Education (en)

Obvious Simplicity  |  15


store), you’d use constructs called hashtables, associative arrays,

maps or tables. In Python, you use something called a dictionary.

Here’s a data dictionary of a small selection of random capital cities:

capital_cities = {

    'China': 'Beijing'

    'Germany': 'Berlin',

    'Greece': 'Athens',

    'Russia': 'Moscow',

    'United Kingdom': 'London',

}  


I’ve simply assigned the dictionary to the 

capital_cities

 object. If

I want to look up a capital city for a certain country, I reference the

country’s name in square brackets next to the object named 

capi


tal_cities

:

capital_cities['China']



'Beijing'

Many programming languages have data structures that work like

Python’s lists and dictionaries; some of them do the obvious thing

and call such constructs “lists” and “dictionaries”; some other lan‐

guages make using such constructs as easy and obvious as Python

(although many don’t). Python’s advantage is that 



it does all three of

these things

: it has useful data structures as a core part of the lan‐

guage, it gives them obvious names, and makes them extraordinarily

easy to use. Such usefulness, simplicity and clarity is another case of

removing barriers to engaging with programming.

As mentioned earlier, Python also does the expected thing. For

example, if I try to sum together an empty dictionary and an empty

list (something that’s obviously wrong—evidence that I’ve misun‐

derstood what I’m trying to do) Python will complain:

>>> {} + []

Traceback (most recent call last):

  File "", line 1, in

TypeError: unsupported operand type(s) for +: 'dict' and 'list' 

This is simply telling me that I can’t use the “+” operand to sum a

dictionary and a list. This is to be expected, rather obvious and quite

helpful.


Nevertheless, other languages try to be less strict and more forgiving

of the programmer. While this may sound like a good idea, it means

that faulty code like that attempted above will be executed without

any error and cause uncertain results (after all, what is the answer of




Download 3,73 Mb.

Do'stlaringiz bilan baham:
1   ...   18   19   20   21   22   23   24   25   ...   37




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