CARVIEW |
Python Variables Quiz
Question 1
How do you concatenate two strings in Python?
str1 . str2
str1 + str2
str1 , str2
concat(str1, str2)
Question 2
What is the purpose of the __dict__ attribute in Python?
To access the dictionary of a list
To store the attributes of an object
To define a dictionary in Python
To convert a dictionary to a list
Question 3
How do you create a dictionary using a comprehension in Python?
{key: value for key, value in iterable}
dict(iterable)
create_dict(iterable)
{key, value in iterable}
Question 4
How do you create a multiline string in Python?
"This is a multiline string"
'This is a multiline string'
"""This is a multiline string"""
(a and b)
Question 5
How do you convert a floating-point number to an integer in Python?
int(number)
float_to_int(number)
number.int()
convert(int, number)
Question 6
How do you convert a list of strings to a single string in Python?
"".join(list)
str(list)
convert(list, str)
" ".join(list)
Question 7
What is the output of the following code?
x = [1, 2, 3, 4]
y = filter(lambda a: a % 2 == 0, x)
print(list(y))
[1, 3]
[2, 4]
[1, 2, 3, 4]
[]
Question 8
What is the purpose of the enumerate() function in Python?
To get the index and value of each item in an iterable
To count the occurrences of an element in an iterable
To enumerate through a list
To enumerate through a dictionary
Question 9
How do you check if a key is present in a dictionary?
key in dictionary
key.exists(dictionary)
dictionary.contains(key)
has_key(key, dictionary)
Question 10
How do you find the length of a list in Python?
len(list)
length(list)
list.length()
count(list)
There are 24 questions to complete.