Python worksheet
**Q1.** What is the correct file extension for Python files?
A) .pt
B) .pyt
C) .py
D) .python
**Q2.** What is the output of `print(type("Hello"))`?
A) int
B) float
C) str
D) char
**Q3.** Which keyword is used to define a function in Python?
A) func
B) define
C) def
D) function
**Q4.** What will `print(3 ** 2)` output?
A) 6
B) 9
C) 8
D) 5
**Q5.** Python is a \_\_\_\_ typed language.
A) statically
B) weakly
C) dynamically
D) strongly
**Q6.** What is the output of: `print(5//2)`?
A) 2.5
B) 3
C) 2
D) Error
**Q7.** Which one is not a valid Python data type?
A) int
B) real
C) str
D) float
**Q8.** Which of the following is used for comments in Python?
A) //
B) /\* \*/
C) #
D)
**Q9.** What is the output of `bool("")`?
A) True
B) False
C) 0
D) Error
**Q10.** Which function is used to take input from the user in Python?
A) scanf()
B) gets()
C) input()
D) read()
**Q11.** The default return value of a function that does not return anything is:
A) 0
B) False
C) null
D) None
**Q12.** Which data type is immutable in Python?
A) list
B) dict
C) tuple
D) set
**Q13.** Which of the following is a Python tuple?
A) \[1, 2, 3]
B) {1, 2, 3}
C) (1, 2, 3)
D) <1, 2, 3>
**Q14.** Which method is used to add an item to a list?
A) add()
B) append()
C) insert()
D) push()
**Q15.** What is the result of `len("Artificial Intelligence")`?
A) 23
B) 24
C) 25
D) 22
**Q16.** Which operator is used for exponentiation in Python?
A) ^
B) \*
C) \*\*
D) %
**Q17.** What will `print('5' + '10')` output?
A) 15
B) 510
C) Error
D) None
**Q18.** Which keyword is used to start a loop in Python?
A) loop
B) repeat
C) for
D) iterate
**Q19.** What will `range(5)` return?
A) \[0, 5]
B) \[0, 1, 2, 3, 4]
C) \[1, 2, 3, 4, 5]
D) None
**Q20.** What is the correct way to define a dictionary in Python?
A) {1: "A", 2: "B"}
B) \[1, "A", 2, "B"]
C) (1 => "A", 2 => "B")
D) dict\[1, "A", 2, "B"]
**Q21.** Which method removes all items from a list?
A) clear()
B) delete()
C) removeAll()
D) empty()
**Q22.** The keyword `elif` stands for:
A) else if
B) else then
C) else only
D) if else
**Q23.** Which is the correct way to declare a variable in Python?
A) int x = 5
B) var x = 5
C) x = 5
D) declare x = 5
**Q24.** Which function gives the number of elements in a list?
A) count()
B) len()
C) size()
D) num()
**Q25.** What does `str(123)` return?
A) 123
B) "123"
C) 1
D) Error
**Q26.** Which of these is used to handle exceptions?
A) try-except
B) if-else
C) catch-throw
D) loop
**Q27.** What is the output of `print(7 % 3)`?
A) 1
B) 2
C) 0
D) 3
**Q28.** Which method converts all characters to lowercase?
A) down()
B) tolower()
C) lower()
D) casefold()
**Q29.** How do you write a single-line comment?
A) // comment
B)
C) -- comment
D) # comment
**Q30.** Which function is used to convert string to integer?
A) str()
B) float()
C) int()
D) input()
**Q31.** Which keyword is used to exit a loop?
A) exit
B) end
C) quit
D) break
**Q32.** Which of the following is a correct Python list?
A) (1,2,3)
B) {1,2,3}
C) \[1,2,3]
D) <1,2,3>
**Q33.** Which of the following is used to create an empty set?
A) {}
B) set()
C) \[]
D) empty()
**Q34.** The output of `type([])` is:
A) dict
B) tuple
C) list
D) set
**Q35.** What is the output of `print(10 != 10)`?
A) True
B) False
C) Error
D) None
**Q36.** Which of these is a membership operator?
A) =
B) in
C) ==
D) not
**Q37.** `x = [1, 2, 3]; print(x[1])` will output:
A) 1
B) 2
C) 3
D) Error
**Q38.** What is the purpose of `pass` in Python?
A) Skip an error
B) Create a delay
C) Do nothing
D) Stop execution
**Q39.** What will `print(True and False)` return?
A) True
B) False
C) 0
D) Error
**Q40.** Python language was developed by:
A) Charles Babbage
B) Guido van Rossum
C) Dennis Ritchie
D) James Gosling
**Q41.** What will be the output of `print(bool(0))`?
A) True
B) False
C) 0
D) Error
**Q42.** Which of the following is not a keyword in Python?
A) for
B) while
C) switch
D) if
**Q43.** What is the use of `is` operator in Python?
A) Checks value
B) Checks memory location
C) Assigns values
D) Adds items
**Q44.** How is indentation done in Python?
A) With semicolon
B) With curly brackets
C) Using whitespace
D) None of these
**Q45.** Python's `input()` returns:
A) int
B) str
C) float
D) None
**Q46.** What does `len({})` return?
A) 0
B) 1
C) None
D) Error
**Q47.** What is the output of `print('A' > 'B')`?
A) True
B) False
C) Error
D) None
**Q48.** How to define a multi-line string?
A) ' ' 'text' ' '
B) """text"""
C) %%text%%
D)
**Q49.** Which of these is not used in decision making?
A) if
B) elif
C) else
D) then
**Q50.** Which function gives the Unicode of a character?
A) char()
B) ord()
C) ascii()
D) unichr()