Python

All Questions for: Python

Question 1: Which of the following is an immutable data type in Python?

  • A List
  • B Set
  • C Tuple
  • D Dictionary

Explanation: Tuples are immutable, while lists, sets, and dictionaries are mutable.

Question 2: Which of the following is the correct way to assign a value to a variable in Python?

  • A x = 10
  • B 10 -> x
  • C int x = 10;

Explanation: The correct option is: Option A

Question 3: Which of the following is the correct way to print "Hello World" in Python 3?

  • A echo "Hello World"
  • B print "Hello World"
  • C print("Hello World")

Explanation: The correct option is: Option C

Question 4: What is the data type of the value True in Python?

  • A string
  • B bool
  • C int

Explanation: The correct option is: Option B

Question 5: If mylist = [10,20,30], what is mylist[1]?

  • A 20
  • B 10
  • C 30

Explanation: The correct option is: Option A

Question 6: Which operator is used to concatenate strings in Python?

  • A *
  • B -
  • C +

Explanation: The correct option is: Option C

Question 7: Which symbol is used to begin a comment in Python?

  • A //
  • B #
  • C /* */

Explanation: The correct option is: Option B

Question 8: Which keyword is used to define a function in Python?

  • A def
  • B func
  • C function

Explanation: The correct option is: Option A

Question 9: In Python, indentation is used for:

  • A Comments
  • B Variable declaration
  • C Defining code blocks

Explanation: The correct option is: Option C

Question 10: What is the result of 7 // 2 in Python?

  • A 3
  • B 3.5
  • C 4

Explanation: The correct option is: Option A

Question 11: Which of the following is a boolean operator in Python?

  • A PLUS
  • B AND
  • C CONCAT

Explanation: The correct option is: Option B

Question 12: Which keyword is used to start a loop that iterates over a sequence in Python?

  • A for
  • B loop
  • C iterate

Explanation: The correct option is: Option A

Question 13: Which keyword is used to start a loop that continues as long as a condition is true in Python?

  • A for
  • B while
  • C loop

Explanation: The correct option is: Option B

Question 14: Which keyword is used to exit a loop prematurely in Python?

  • A exit
  • B stop
  • C break

Explanation: The correct option is: Option C

Question 15: Which keyword is used to skip the current iteration of a loop and continue with the next?

  • A skip
  • B continue
  • C next

Explanation: The correct option is: Option B

Question 16: Which of the following is the correct way to define a dictionary in Python?

  • A mydict = {"a":1, "b":2}
  • B mydict = ["a":1, "b":2]
  • C mydict = ("a":1, "b":2)

Explanation: The correct option is: Option A

Question 17: Which of the following creates a set in Python?

  • A s = []
  • B s = {}
  • C s = set([1,2,3])

Explanation: The correct option is: Option C

Question 18: Which function is used to take input from the user in Python?

  • A input()
  • B scan()
  • C get()

Explanation: The correct option is: Option A

Question 19: Which of the following converts a string to an integer in Python?

  • A str()
  • B int()
  • C float()

Explanation: The correct option is: Option B

Question 20: Which function returns the number of items in a list in Python?

  • A size()
  • B count()
  • C len()

Explanation: The correct option is: Option C

Question 21: Which keyword is used for exception handling in Python?

  • A try
  • B catch
  • C exception

Explanation: The correct option is: Option A