18 Questions
What is the purpose of the len() function in Python?
To get the number of characters in a string
How do you access a character in a string in Python?
By using the string name followed by the index in square brackets
What is the syntax for slicing in Python?
[start:end:step]
What operation is performed on strings using the + symbol?
Concatenation
What is the difference between '2' and 2 in Python?
'2' is a string and 2 is an integer
What happens when you try to concatenate a string with an integer in Python?
It returns a TypeError
What is the purpose of the str() function in Python?
To convert an integer to a string
What is the result of using a string method on a string in Python?
A new string is created with the modified result
What is the purpose of the len() function in Python?
To get the length of a list or string
How do you check if an item is present in a list in Python?
Using the in operator
What is the difference between a list and a tuple in Python?
A list is mutable, a tuple is immutable
What is the purpose of the append() method in a list in Python?
To add an item at the end of a list
What is the primary difference between a list and a dictionary in Python?
Dictionaries can have non-integer indices
How do you get all the keys in a dictionary?
Using the keys()
method
What is the purpose of the items()
method in a dictionary?
To get all the key-value pairs in a dictionary
How do you check if a key exists in a dictionary?
Using the in
operator on the dictionary
How do you convert a list of tuples into a dictionary?
Using the dict()
function
How do you store dictionary keys in a list?
Using the list()
function
This quiz covers string concatenation, converting integers to strings, and string methods in Python, as well as basic concepts of lists.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free