Python Programming Literacy (Beginner Level) Flashcards

1
Q

Code Editor:
some_string = “Python”
a, b, c, d = some_string

A

This is an error, “too many values to unpack”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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’]

A

KeyError: ‘Tim’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A set in Python can contain which of the following data types?

A

it contains floats, tuples and strings

**it does not contain lists, dictionaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why can classes be considered analogous to blueprints?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What kind of relationship is inheritance used to model?

A

Is-a relationship

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following is considered to be an advantage of object-oriented programming?

A

Models real-world entities

Modular structure for code

Promotes code reuse

Data encapsulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following statement(s) about return values is/are false?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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?

A

The keys in the dictionary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A list of strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of these keywords has no effect on code execution when used in for loops?

A

pass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which TWO of the following statements about conditional breakpoints are TRUE?

A

It pauses code execution only when the specified condition is True

The condition specified may reference variables in the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

similarities in List and Tuple

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly