100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4,6 TrustPilot
logo-home
Notas de lectura

Python module 3 notes for 1st year students,

Puntuación
-
Vendido
-
Páginas
21
Subido en
11-06-2025
Escrito en
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

Institución
Grado










Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
11 de junio de 2025
Número de páginas
21
Escrito en
2024/2025
Tipo
Notas de lectura
Profesor(es)
Kamala cr
Contiene
Todas las clases

Temas

Vista previa del contenido

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.
$8.49
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
sidduteli

Conoce al vendedor

Seller avatar
sidduteli Bapuji institute of engineering and technology
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
0
Miembro desde
7 meses
Número de seguidores
0
Documentos
2
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes