Py4e: Chapter 8- Questions and Answers|
Latest Update
What are the Python keywords used to construct a loop to iterate through a list? for / in
For the following list, how would you print out 'Sally'?
friends = [ 'Joseph', 'Glenn', 'Sally' ] print(friends[2])
What would the following Python code print out?
fruit = 'Banana'
fruit[0] = 'b'
print(fruit) Nothing would print - the program fails with a traceback
Which of the following Python statements would print out the length of a list stored in the
variable data? print(len(data))
What type of data is produced when you call the range() function?
x = range(5) A list of integers
What does the following Python code print out?
a = [1, 2, 3]
b = [4, 5, 6]
c=a+b
Latest Update
What are the Python keywords used to construct a loop to iterate through a list? for / in
For the following list, how would you print out 'Sally'?
friends = [ 'Joseph', 'Glenn', 'Sally' ] print(friends[2])
What would the following Python code print out?
fruit = 'Banana'
fruit[0] = 'b'
print(fruit) Nothing would print - the program fails with a traceback
Which of the following Python statements would print out the length of a list stored in the
variable data? print(len(data))
What type of data is produced when you call the range() function?
x = range(5) A list of integers
What does the following Python code print out?
a = [1, 2, 3]
b = [4, 5, 6]
c=a+b