Python Variables Quiz

Last Updated :
Discuss
Comments

Question 1

How do you concatenate two strings in Python?

  • A

    str1 . str2

  • B

    str1 + str2

  • C

    str1 , str2

  • D

    concat(str1, str2)

Question 2

What is the purpose of the __dict__ attribute in Python?

  • A

    To access the dictionary of a list

  • B

    To store the attributes of an object

  • C

    To define a dictionary in Python

  • D

    To convert a dictionary to a list

Question 3

How do you create a dictionary using a comprehension in Python?

  • A

    {key: value for key, value in iterable}

  • B

    dict(iterable)

  • C

    create_dict(iterable)

  • D

    {key, value in iterable}

Question 4

How do you create a multiline string in Python?

  • A

    "This is a multiline string"

  • B

    'This is a multiline string'

  • C

    """This is a multiline string"""

  • D

    (a and b)

Question 5

How do you convert a floating-point number to an integer in Python?

  • A

    int(number)

  • B

    float_to_int(number)

  • C

    number.int()

  • D

    convert(int, number)

Question 6

How do you convert a list of strings to a single string in Python?

  • A

     "".join(list)

  • B

     str(list)

  • C

    convert(list, str)

  • D

    add(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))
 

  • A

     [1, 3]

  • B

     [2, 4]

  • C

    [1, 2, 3, 4]

  • D

     []

Question 8

What is the purpose of the enumerate() function in Python?

  • A

    To get the index and value of each item in an iterable

  • B

    To count the occurrences of an element in an iterable

  • C

    To enumerate through a list

  • D

    To enumerate through a dictionary

Question 9

How do you check if a key is present in a dictionary?
 

  • A

    key in dictionary

  • B

    key.exists(dictionary)

  • C

    dictionary.contains(key)

  • D

    has_key(key, dictionary)

Question 10

How do you find the length of a list in Python?

  • A

    len(list)

  • B

    length(list)

  • C

    list.length()

  • D

    count(list)

There are 24 questions to complete.

Take a part in the ongoing discussion