Online Exam Quiz

questionQuestion  1 to 30

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 correct way to get the length of a string?

  • length()
  • size()
  • len()
  • count()
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

How do you find the index of an element in a list?

  • index()
  • find()
  • locate()
  • position()
Mark for review

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

  • remove()
  • delete()
  • discard()
  • pop()
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

How do you check for equality in Python?

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

How do you write an if statement in Python?

  • if x > y then:
  • if x > y {
  • if x > y:
  • if (x > y)
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

What is the correct way to get the first element in a list?

  • list[0]
  • list(0)
  • list.first()
  • list[1]
Mark for review

How do you concatenate strings in Python?

  • "Hello" + "World"
  • "Hello" . "World"
  • "Hello" & "World"
  • "Hello" - "World"
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

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

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

How do you convert a list to a tuple?

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

What is the correct way to check if an object is an instance of a class?

  • isinstance(object, class)
  • isobject(class)
  • checkinstance(object, class)
  • isobjectinstance(object, class)
Mark for review

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

  • 7
  • 77
  • 777
  • 7777
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

What is the correct way to create an empty set in Python?

  • set = {}
  • set = ()
  • set = []
  • set = set()
Mark for review

How do you create a nested dictionary in Python?

  • dict = {"child1": {"name": "Emil", "year": 2004}, "child2": {"name": "Tobias", "year": 2007}}
  • dict = {"child1" => {"name": "Emil", "year": 2004}, "child2" => {"name": "Tobias", "year": 2007}}
  • dict = {"child1" : ("name": "Emil", "year": 2004), "child2" : ("name": "Tobias", "year": 2007)}
  • dict = {"child1", "name": "Emil", "year": 2004}, {"child2", "name": "Tobias", "year": 2007}
Mark for review

How do you write a multiline comment in Python?

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

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

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

How can you add an element to a list?

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

What is the correct syntax to import a module named "math"?

  • import math
  • import.math
  • using math
  • include math
Mark for review

What is the output of print("Hello"[1])?

  • H
  • e
  • l
  • o
Mark for review

How do you create a class in Python?

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

Which keyword is used to define a lambda function?

  • lambda
  • def
  • func
  • function
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

What is the correct file extension for Python files?

  • .pyt
  • .pt
  • .pyth
  • .py
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 method is used to remove whitespace from the beginning and end of a string?

  • strip()
  • trim()
  • lstrip()
  • rstrip()
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