Online Exam Quiz

questionQuestion  1 to 30

What is the correct way to create a dictionary in Python?

  • dict = {"name": "John", "age": 36}
  • dict = ["name": "John", "age": 36]
  • dict = "name" => "John", "age" => 36
  • dict = ("name": "John", "age": 36)
Mark for review

What is the output of print(3 * "7")?

  • 7
  • 77
  • 777
  • 7777
Mark for review

What is the correct way to create a set in Python?

  • set = {"apple", "banana", "cherry"}
  • set = ("apple", "banana", "cherry")
  • set = ["apple", "banana", "cherry"]
  • set = {"apple": "banana", "cherry"}
Mark for review

Which keyword is used to create a function in Python?

  • func
  • function
  • def
  • define
Mark for review

Which method can be used to convert a string to lowercase?

  • toLowerCase()
  • lower()
  • toLower()
  • downcase()
Mark for review

How do you create a variable with the numeric value 5?

  • x = 5
  • x == 5
  • x := 5
  • x === 5
Mark for review

What is the output of print(2**3)?

  • 6
  • 8
  • 9
  • 12
Mark for review

What is the correct syntax to output the type of a variable or object in Python?

  • print(typeOf(x))
  • print(type(x))
  • print(typeof x)
  • print(typeof(x))
Mark for review

Which of the following is used to iterate over items of a list in Python?

  • for
  • foreach
  • while
  • loop
Mark for review

How do you start a comment in Python?

  • //
  • #
  • <!--
  • /*
Mark for review

Which function is used to convert an integer to a string?

  • str()
  • int()
  • toString()
  • convert()
Mark for review

How do you write a single-line comment in Python?

  • // comment
  • # comment
  • <!-- comment -->
  • /* comment */
Mark for review

How can you add an element to a list?

  • append()
  • add()
  • insert()
  • push()
Mark for review

How do you access the first element of a dictionary by its key?

  • dict["key"]
  • dict(0)
  • dict[1]
  • dict.first()
Mark for review

How do you create a tuple in Python?

  • tuple = ("apple", "banana", "cherry")
  • tuple = ["apple", "banana", "cherry"]
  • tuple = "apple", "banana", "cherry"
  • tuple = {apple, banana, cherry}
Mark for review

What is the output of print(type("Hello"))?

  • <type 'string'>
  • <class 'str'>
  • <class 'string'>
  • <type 'str'>
Mark for review

Which function can be used to read user input from the console?

  • input()
  • scan()
  • cin()
  • read()
Mark for review

Which keyword is used to define a block of code that will be executed if an exception occurs?

  • else
  • finally
  • except
  • error
Mark for review

What is the correct way to get the length of a string?

  • length()
  • size()
  • len()
  • count()
Mark for review

How do you convert a list to a tuple?

  • tuple(list)
  • list(tuple)
  • to_tuple(list)
  • convert(list)
Mark for review

How do you create a virtual environment in Python?

  • virtualenv venv
  • python -m venv venv
  • create venv
  • mkvirtualenv venv
Mark for review

What is the correct way to remove an item from a list in Python?

  • remove()
  • delete()
  • discard()
  • pop()
Mark for review

Which method is called when an object is created?

  • start
  • init
  • create
  • new
Mark for review

What does the len() function do?

  • Returns the number of characters in a string
  • Returns the number of items in an object
  • Returns the length of a number
  • Returns the length of a file
Mark for review

What is the correct way to handle exceptions in Python?

  • try/except
  • try/catch
  • do/except
  • try/error
Mark for review

Which method is used to remove whitespace from the beginning and end of a string?

  • strip()
  • trim()
  • lstrip()
  • rstrip()
Mark for review

How do you check for equality in Python?

  • a = b
  • a == b
  • a equal b
  • a === b
Mark for review

How do you start a for loop in Python?

  • for i in range(6)
  • for i to range(6)
  • for i = 1 to 6
  • for (i = 0; i < 6; i++)
Mark for review

How do you create a class in Python?

  • class MyClass:
  • MyClass class:
  • create MyClass:
  • define MyClass:
Mark for review

How do you create a new file in Python?

  • open("filename", "w")
  • open("filename", "create")
  • openFile("filename", "w")
  • openFile("filename", "create")
Mark for review

blinkerOnline

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • Answered
  • Not Answered
  • Marked for Review