Python Programming Literacy (Beginner Level) Flashcards
Code Editor:
some_string = “Python”
a, b, c, d = some_string
This is an error, “too many values to unpack”
Question: Consider a dictionary of names and ages set up as below:
Code Editor:
names_ages = {‘John’: 35, ‘Jim’: 45, ‘Alice’: 25}
What would the output be if you were to run this code?
names_ages[‘Tim’]
KeyError: ‘Tim’
A set in Python can contain which of the following data types?
it contains floats, tuples and strings
**it does not contain lists, dictionaries
Why can classes be considered analogous to blueprints?
Is a template which defines how entities which follow that template look and behave
Specifies charactistics of all objects or instances which are built using that blueprint
What kind of relationship is inheritance used to model?
Is-a relationship
Which of the following is considered to be an advantage of object-oriented programming?
Models real-world entities
Modular structure for code
Promotes code reuse
Data encapsulation
Which of the following statement(s) about return values is/are false?
A function with input arguments cannot have a return statemen
A function has to have a return statement
A function is limited to having exactly one return statement
Given a variable my_dict which is a dictionary, consider you use it in a for loop in this manner:
for x in my_dict:
print (x)
What are the contents printed out?
The keys in the dictionary
Given the following code, what is the type of x which is printed out in each iteration?
my_list = [[‘tiger’, ‘lion’, ‘leopard’], [‘camel’, ‘llama’, ‘alpaca’], [‘zebra’, ‘donkey’, ‘wildebeest’]]
for x in my_list:
print(x)
A list of strings
Which of these keywords has no effect on code execution when used in for loops?
pass
Which TWO of the following statements about conditional breakpoints are TRUE?
It pauses code execution only when the specified condition is True
The condition specified may reference variables in the code
similarities in List and Tuple
ordered collection of elements
can contain elements of different data types
elements are accessed using index values starting from zero
slicing operations can be done in both