100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
College aantekeningen

Python module 3 notes for 1st year students,

Beoordeling
-
Verkocht
-
Pagina's
21
Geüpload op
11-06-2025
Geschreven in
2024/2025

Python programming language along with synonyms for students is covered in my document uploaded.For 1st year students this document will help and a CAED notes also uploaded

Instelling
Vak










Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
11 juni 2025
Aantal pagina's
21
Geschreven in
2024/2025
Type
College aantekeningen
Docent(en)
Kamala cr
Bevat
Alle colleges

Onderwerpen

Voorbeeld van de inhoud

Module 3 Python



CHAPTER 5: DICTIONARIES AND STRUCTURING DATA
1. The Dictionary Data Type
2. Pretty Printing
3. Using Data Structures to Model Real-World Things.


The Dictionary Data Type
 A dictionary is a collection of many values. Indexes for dictionaries can use many different data
types, not just integers. Indexes for dictionaries are called keys, and a key with its associated value
is called a key-value pair.
 A dictionary is typed with braces, {}.



 This assigns a dictionary to the myCat variable. This dictionary’s keys are 'size', 'color', and
'disposition'. The values for these keys are 'fat', 'gray', and 'loud', respectively. You can access these
values through their keys:




 Dictionaries can still use integer values as keys, but they do not have to start at 0 and can be any
number.

, Module 3 Python

Dictionaries vs. Lists
 Unlike lists, items in dictionaries are unordered.
 The first item in a list named spam would be spam[0]. But there is no “first” item in a dictionary.
While the order of items matters for determining whether two lists are the same, it does not matter
in what order the key-value pairs are typed in a dictionary.




 Trying to access a key that does not exist in a dictionary will result in a KeyError error message,
much like a list’s “out-of-range” IndexError error message.




 We can have arbitrary values for the keys that allows us to organize our data in powerful ways.
 Ex: we want to store data about our friends’ birthdays. We can use a dictionary with the names as
keys and the birthdays as values.




Program Output
 We create an initial dictionary and store it in birthdays 1.
 We can see if the entered name exists as a key in the dictionary with the in keyword 2.
 If the name is in the dictionary, we access the associated value using square brackets 3; if not, we
can add it using the same square bracket syntax combined with the assignment operator 4.

, Module 3 Python

The keys(), values(), and items() Methods
 There are three dictionary methods that will return list-like values of the dictionary’s keys, values,
or both keys and values: keys(), values(), and items().
 Data types (dict_keys, dict_values, and dict_items, respectively) can be used in for loops.




 A for loop can iterate over the keys, values, or key-value pairs in a dictionary by using keys(),
values(), and items() methods.
 The values in the dict_items value returned by the items() method are tuples of the key and value.




 If we want a true list from one of these methods, pass its list-like return value to the list() function.




 The list(spam.keys()) line takes the dict_keys value returned from keys() and passes it to list(),
which then returns a list value of ['color', 'age'].
 We can also use the multiple assignment trick in a for loop to assign the key and value to separate
variables.
€7,53
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
sidduteli

Maak kennis met de verkoper

Seller avatar
sidduteli Bapuji institute of engineering and technology
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
0
Lid sinds
7 maanden
Aantal volgers
0
Documenten
2
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen