Home > Python > Quizzes > Python Programming Basics Practice Test: Different Types Of Python Strings
Python Programming Basics Practice Test: Different Types Of Python Strings
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “What will be the output of the following Python code?”
There are three different string types in Python: str (Unicode strings): These are the most common type of string and are used to represent text. They can be enclosed in either single or double quotes. bytes (binary strings): These strings are used to represent binary data, such as images or audio files. They are enclosed in single quotes and prefixed with a 'b'. bytearray (mutable binary strings): These strings are similar to bytes strings, but they can be modified. They are enclosed in square brackets and prefixed with a 'b'. String Literals: String literals are used to represent text... Show more
Python Programming Basics Practice Test: Different Types Of Python Strings
Time left 00:00
25 Questions

1. What will be the output of the following Python code?
print('xyyzxxyxyy'.lstrip('xyy'))
2. What will be the output of the following Python code snippet?
print('abc'.islower())
3. What will be the output of the following Python code snippet?
print('Hello World'.istitle())
4. What will be the output of the following Python code snippet?
print(''.isdigit())
5. What will be the output of the following Python code snippet?
print('abef'.replace('cd', '12'))
6. What will be the output of the following Python code snippet?
print('The sum of {0} and {1} is {2}'.format(2, 10, 12))
7. What will be the output of the following Python code snippet?
print('1.1'.isnumeric())
8. What will be the output of the following Python code?
>>>print("D", end = ' ')
>>>print("C", end = ' ')
>>>print("B", end = ' ')
>>>print("A", end = ' ')
9. What arithmetic operators cannot be used with strings?
10. What will be the output of the following Python code?
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))
11. What will be the output of the following Python code snippet?
print('xyyxyyxyxyxxy'.replace('xy', '12', 0))
12. What function do you use to read a string?
13. What will be the output of the following Python code?
>>>print (r"\nhello")
14. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
15. What will be the output of the following Python code?
print('*', "abcde".center(6), '*', sep='')
16. What will be the output of the following Python code?
print('abcdefcdgh'.partition('cd'))
17. What will be the output of the following Python code?
print('cba'.maketrans('abc', '123'))
18. What will be the output of the following Python statement?
>>>print(chr(ord('b')+1))
19. What will be the output of the following Python code?
class Count:
def __init__(self, count = 0):
self.__count = count
 
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
 
s1 = "Good"
s2 = "Good"
print(id(s1) == id(s2))
20. If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.
21. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 2))
22. What will be the output of the following Python code?
print('*', "abcdef".center(7), '*')
23. What will be the output of the following Python code snippet?
print(''''''.isspace())
24. What will be the output of the following Python code?
print("Hello {} and {}".format('foo', 'bin'))
25. To check whether string s1 contains another string s2, use ________