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?
>>>example = "helle"
>>>example.find("e")
2. To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
3. What will be the output of the following Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
4. What will be the output of the following Python code?
>>>example = "helle"
>>>example.rfind("e")
5. What will be the output of the following Python code?
>>>max("what are you")
6. What will be the output of the following Python code?
>>>print("D", end = ' ')
>>>print("C", end = ' ')
>>>print("B", end = ' ')
>>>print("A", end = ' ')
7. What will be the output of the following Python code?
print("abcdef".center(7, '1'))
8. What will be the output of the following Python code?
print('{0:.2}'.format(1/3))
9. What will be the output of the following Python code?
class tester:
def __init__(self, id):
self.id = str(id)
id="224"
 
>>>temp = tester(12)
>>>print(temp.id)
10. What will be the output of the following Python code?
class Name:
def __init__(self, firstName, mi, lastName):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
 
firstName = "John"
name = Name(firstName, 'F', "Smith")
firstName = "Peter"
name.lastName = "Pan"
print(name.firstName, name.lastName)
11. What will be the output of the following Python code?
print('ab,12'.isalnum())
12. What will be the output of the following Python code?
print('cba'.maketrans('abc', '123'))
13. What will be the output of the following Python code?
print("abcdef".find("cd") == "cd" in "abcdef")
14. What will be the output of the following Python code?
print("Hello {} and {}".format('foo', 'bin'))
15. What will be the output of the following Python code?
print('*', "abcdef".center(7), '*')
16. What will be the output of the following Python code?
print('xyyzxxyxyy'.lstrip('xyy'))
17. What will be the output of the following Python code snippet?
print('HelloWorld'.istitle())
18. What will be the output of the following Python code?
print("abcdef".center(7, 1))
19. What will be the output of the following Python code?
print("abcdef".find("cd"))
20. What will be the output of the following Python code?
print('xyxxyyzxxy'.lstrip('xyy'))
21. Say s=”hello” what will be the return value of type(s)?
22. What will be the output of the following Python code snippet?
print('__foo__'.isidentifier())
23. The output of executing string.ascii_letters can also be achieved by:
24. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 0, 100))
25. What will be the output of the following Python code snippet?
print('\t'.isspace())