Skip to content
- Which of the following is the correct file extension for Python files?
- a) .python
- b) .py
- c) .pt
- d) .p
- What is the correct syntax to output “Hello, World” in Python?
- a) print(“Hello, World”)
- b) echo “Hello, World”
- c) console.log(“Hello, World”)
- d) printf(“Hello, World”)
- How do you insert a comment in Python?
- a) // This is a comment
- b) /* This is a comment */
- c) # This is a comment
- d) <!– This is a comment –>
- Which of the following data types is not supported in Python?
- a) Lists
- b) Tuples
- c) Arrays
- d) Sets
- What is the keyword used to define a function in Python?
- a) func
- b) define
- c) def
- d) function
- What will be the output of the following code:
print(type(5))?
- a) int
- b) str
- c) float
- d) class
- Which of the following is the correct way to create a list in Python?
- a) list = (1, 2, 3)
- b) list = [1, 2, 3]
- c) list = {1, 2, 3}
- d) list = <1, 2, 3>
- How can you create a dictionary in Python?
- a) dict = [1: “one”, 2: “two”]
- b) dict = {1: “one”, 2: “two”}
- c) dict = (1: “one”, 2: “two”)
- d) dict = <1: “one”, 2: “two”>
- What keyword is used to create a conditional statement in Python?
- a) if
- b) when
- c) else
- d) switch
- Which operator is used for exponentiation in Python?
- What will be the result of
3 * 2 ** 2?
- How do you start a while loop in Python?
- a) while (x < y) {
- b) while x < y:
- c) while x < y
- d) while (x < y):
- Which of the following is used to handle exceptions in Python?
- a) try
- b) catch
- c) handle
- d) except
- What is the output of
len("Python")?
- Which of the following keyword is used to exit a loop in Python?
- a) exit
- b) break
- c) stop
- d) continue
- How do you create a class in Python?
- a) class MyClass:
- b) MyClass class:
- c) class: MyClass
- d) MyClass = class()
- What is the correct way to call a function named
my_function?
- a) my_function[]
- b) my_function{}
- c) my_function()
- d) my_function;
- Which function is used to read a file in Python?
- a) readfile()
- b) open()
- c) read()
- d) get()
- What will be the output of
print("hello" + "world")?
- a) helloworld
- b) hello world
- c) hello+world
- d) hello world!
- How do you find the maximum value in a list?
- a) max(list)
- b) list.max()
- c) maximum(list)
- d) list.maximum()
- Which of the following statements about Python’s
pass statement is true?
- a) It is used to exit a loop.
- b) It does nothing and is a placeholder.
- c) It breaks a function.
- d) It continues to the next iteration of a loop.
- How do you define a private variable in Python?
- a) _variable
- b) #variable
- c) $variable
- d) variable
- What is the length of the list
[1, 2, 3, 4, 5]?
- Which keyword is used to import a module in Python?
- a) include
- b) import
- c) require
- d) use
- What will be the output of
print(0.1 + 0.2 == 0.3)?
- a) True
- b) False
- c) None
- d) Error
- What is an immutable data type in Python?
- a) List
- b) Set
- c) Dictionary
- d) Tuple
- Which of the following is a built-in data type in Python?
- a) char
- b) bool
- c) string
- d) all of the above
- How do you write a single-line comment in Python?
- a) // Comment
- b) # Comment
- c) — Comment
- d) /* Comment */
- Which module is used for regular expressions in Python?
- a) regex
- b) re
- c) regexes
- d) regular
- What keyword is used to define a constant in Python?
- a) const
- b) final
- c) constant
- d) None (Python does not have a constant keyword)
- How do you delete an element from a list in Python?
- a) remove(element)
- b) del list[element]
- c) list.remove(element)
- d) all of the above
- Which of the following denotes a dictionary in Python?
- How can you check if a key exists in a dictionary?
- a) key in dictionary
- b) dictionary.has_key(key)
- c) key in dictionary.keys()
- d) all of the above
- What does the
break statement do in a loop?
- a) Skips the rest of the current iteration
- b) Exits the loop
- c) Continues with the next iteration
- d) Terminates the program
- What is the output of
print("Python"[0])?
- a) P
- b) p
- c) Python
- d) Error
- Which of the following will NOT raise an error?
- a) True + 1
- b) “1” + 1
- c) 1 + 1
- d) “Hello” + 5
- Which Python statement is used for iteration?
- a) loop
- b) for
- c) iterate
- d) iterate for
- To create a new file in Python, what mode do you use?
- a) “r”
- b) “w”
- c) “a”
- d) “r+”
- How do you convert a string into a list in Python?
- a) str.split()
- b) list(str)
- c) list.split(str)
- d) all of the above
- What will
print("Hello, " * 3) output?
- a) Hello, Hello, Hello,
- b) Hello, Hello, Hello
- c) Hello Hello Hello
- d) Hello, , Hello, , Hello,
- Which symbol is used for floor division in Python?
- What will the following code print?
print(["Python", "is", "fun"][1])
- a) Python
- b) is
- c) fun
- d) Error
- What type of loop executes at least once?
- a) for loop
- b) while loop
- c) do-while loop
- d) infinite loop
- Which of these is NOT a valid variable name in Python?
- a) my_variable
- b) 2nd_variable
- c) variable2
- d) myVariable
- How do you define a method inside a class?
- a) Using
def keyword
- b) Using
method keyword
- c) Using
function keyword
- d) Methods cannot be defined in a class
- What is the result of the following code?
print([1, 2, 3] + [4, 5, 6])
- a) [1, 2, 3, 4, 5, 6]
- b) [1, 2, 3] + [4, 5, 6]
- c) [4, 5, 6, 1, 2, 3]
- d) Error
- Which built-in Python function can be used to iterate over a sequence?
- a) loop()
- b) iterate()
- c) for()
- d) None of the above
- How do you declare a global variable in Python?
- a) global variable_name
- b) declare variable_name
- c) var variable_name
- d) set variable_name
- What will be the output of
print(type([1, 2, 3]))?
- a) list
- b) array
- c) dict
- d) tuple
- Which of the following is used to define a generator in Python?
- a) yield
- b) return
- c) generate
- d) all of the above