Learn Python MCQs

Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.

What is the output of print(5 | 3)?

1) 7

2) 8

3) 6

4) None

Answer : 7

How do you get the current working directory in Python?

1) os.getcwd()

2) getcwd()

3) os.current_directory()

4) None of the above

Answer : os.getcwd()

Which of the following methods can be used to add elements to a list?

1) append()

2) insert()

3) extend()

4) All of the above

Answer : All of the above

What is the output of print("abc" * 2)?

1) abcabc

2) Error

3) None

4) abc + abc

Answer : abcabc

How do you check if a variable is of a specific type in Python?

1) isinstance(var, type)

2) type(var) == type

3) var.type() == type

4) None of the above

Answer : isinstance(var, type)

What is the output of print(sorted([3, 1, 2]))?

1) [1, 2, 3]

2) [3, 2, 1]

3) Error

4) None

Answer : [1, 2, 3]

How do you concatenate two lists in Python?

1) list1 + list2

2) list1.append(list2)

3) list1.extend(list2)

4) None of the above

Answer : list1 + list2

What is the output of print("Hello".replace("e", "a"))?

1) Hallo

2) Hello

3) Error

4) Halla

Answer : Hallo

How do you check if a string is a palindrome in Python?

1) s == s[::-1]

2) s.is_palindrome()

3) s == reverse(s)

4) None of the above

Answer : s == s[::-1]

What is the output of print(abs(-10))?

1) 10

2) -10

3) Error

4) None

Answer : 10