Chapter 6 Quiz >> Python Data Structures
1.What does the following Python Program print out?
str1 = "Hello"
str2 = 'there'
bob = str1 + str2
print(bob)
- Hello
- Hello there
- Hellothere
- Hello
there
2. What does the following Python program print out?
x = '40'
y = int(x) + 2
print(y)
- 42
- x2
- 402
- int402
3. How would you use the index operator [] to print out the letter q from the following string?
x = 'From [email protected]'
- print(x[7])
- print x[-1]
- print(x[q])
- print(x[8])
- print(x[9])
4.How would you use string slicing [:] to print out ‘uct’ from the following string?
x = 'From [email protected]'
- print(x[15:18])
- print(x[14:3])
- print(x[14:17])
- print(x[14/17])
- print(x[15:3])
- print(x[14+17])
5. What is the iteration variable in the following Python code?
for letter in 'banana' :
print(letter)
- ‘banana’
- in
- letter
- for
6. What does the following Python code print out?
print(len('banana')*7)
- banana7
- 42
- 0
- bananabananabananabananabananabananabanana
7. How would you print out the following variable in all upper case in Python?
greet = 'Hello Bob'
print(upper(greet))
int i=0;
char c;
while (greet[i]){
c=greet[i];
putchar(toupper(c));
i++;
}
✅ print(greet.upper())
puts(greet.ucase);
8. Which of the following is not a valid string method in Python?
- twist()
- startswith()
- join()
- split()
9. What will the following Python code print out?
- mar
- uct
- Sat
- .ma
10. Which of the following string methods removes whitespace from both the beginning and end of a string?
- wsrem()
- strtrunc()
- strip()
- split()