cmp (function to compare dictionaries): A built-in function in Python (up to Python 2) that compares two dictionaries and returns an integer indicating their relative order or equality. It helps determine whether dictionaries are equal or which one is greater based on their contents. (Note: In Python 3, cmp() is removed, and comparison is done via operators.)
keys() (dictionary method to get all keys): A method that returns a view object containing all the keys in a dictionary. It allows iteration over keys and is useful for checking key existence or retrieving all keys for processing. Example: dict.keys().
dict() (dictionary creation from sequence of tuples): A constructor that creates a dictionary from a sequence (like a list) of key-value pairs represented as tuples. It converts the sequence into a dictionary with keys mapped to their respective values. Example: dict([('a', 1), ('b', 2)]).
1. How do you create a Python dictionary from a list of key-value pair tuples?
2. What is the purpose of the 'cmp()' function in Python 2 when used with dictionaries?
3. Who is credited with describing the `format()` method and format specifiers `!r` and `!s` in Python string formatting?
Dictionary comparison — method?
Use `==` for equality; `cmp()` in Python 2.
keys() — returns?
A view object of all dictionary keys.
dict() — creates?
A dictionary from sequences of key-value pairs.
KeyError — when?
Accessing a non-existent dictionary key.
String format() — purpose?
Insert variables into strings dynamically.
!r and !s — in format?
Control object representation: repr() vs str().
A ficha de revisão cobre os conceitos essenciais de Python Data Handling and String Formatting. Está organizada por tópicos para facilitar o aprendizado e a memorização, com definições chave, explicações e resumos.
Leia a ficha completa →O quiz contém 10 perguntas de múltipla escolha com correções e explicações detalhadas para cada resposta. Ideal para testar seu conhecimento e identificar lacunas.
Faça o quiz (10 perguntas) →Revizly oferece 20 flashcards interativos sobre Python Data Handling and String Formatting. Cada cartão apresenta uma pergunta na frente e a resposta no verso, permitindo uma revisão ativa e eficaz baseada na repetição espaçada.
Veja todos os 20 flashcards →Bases de données
Bases de données
Bases de données
Programmation
Import your PDF or paste your course, AI generates sheets, quizzes and flashcards in 30 seconds.