Online Exam Quiz

questionQuestion  1 to 30

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

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

What is the correct way to return multiple values from a function?

  • return a, b
  • return [a, b]
  • return (a, b)
  • return {a, b}
Mark for review

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

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

Which keyword is used to check if a value is present in a list, tuple, etc.?

  • exists
  • in
  • on
  • ispresent
Mark for review

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

  • input()
  • scan()
  • cin()
  • read()
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 of the following is used to iterate over items of a list in Python?

  • for
  • foreach
  • while
  • loop
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

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

  • toLowerCase()
  • lower()
  • toLower()
  • downcase()
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

How can you add an element to a list?

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

What is the correct way to handle exceptions in Python?

  • try/except
  • try/catch
  • do/except
  • try/error
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 an if statement in Python?

  • if x > y then:
  • if x > y {
  • if x > y:
  • if (x > y)
Mark for review

How do you write a multiline comment in Python?

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

How do you concatenate strings in Python?

  • "Hello" + "World"
  • "Hello" . "World"
  • "Hello" & "World"
  • "Hello" - "World"
Mark for review

Which of the following is the correct way to open a file for reading in Python?

  • open("filename", "r")
  • open("filename", "read")
  • openFile("filename", "r")
  • openFile("filename", "read")
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 start a comment in Python?

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

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

  • H
  • e
  • l
  • o
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(2**3)?

  • 6
  • 8
  • 9
  • 12
Mark for review

What is the output of print(10 // 3)?

  • 3.33
  • 3
  • 4
  • 2
Mark for review

How do you create a class in Python?

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

Which method can be used to return the length of a list?

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

What is the correct syntax for defining a class in Python?

  • class ClassName:
  • define ClassName:
  • def ClassName:
  • className Class:
Mark for review

Which method is called when an object is created?

  • start
  • init
  • create
  • new
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 way to get the first element in a list?

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

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

  • str()
  • int()
  • toString()
  • convert()
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