Best Python Quizzes for Beginners


Beginners friendly Python Quizzes

Explore the world of Python programming with our beginner-friendly Python quizzes! Test your knowledge and reinforce key concepts through various engaging questions. Whether you’re just starting out or looking to refresh your skills, our interactive quizzes cover the basics of Python syntax, data types, and control flow statements.

Python Quizzes for Beginners

Question 101.

What is the output of the following code?

text = 'Logical' * (6//2)
print(text)
  • LogicalLogicalLogical
  • LogicalLogicalLogicalLogicalLogicalLogical
  • LogicalLogical
  • Error

a. LogicalLogicalLogical


Question 102.

What is the output of the following code?

name = ['Tim', 'James', 'Steve']
name.append(2, 'Bill')
print(name)
  • [‘Tim’, ‘James’, ‘Steve’, ‘Bill’]
  • [‘Tim’, ‘James’, ‘Bill’, ‘Steve’]
  • [‘Tim’, ‘Bill’, ‘James’, ‘Steve’]
  • Error

d. Error


Question 103.

What is the output of the following code?

a = 40 / 10 * (4 + 6) * (6 + 4)
print(a)
  • 200
  • 20
  • 400.0
  • 40.0

c. 400.0


Question 104.

What is the output of the following code?

item1 = [10, 20, 'a', 'b']
item2 = [10, 20, 'a', 'b']

print(item1 == item2, item1 is item2)
  • True False
  • False True
  • True True
  • False False

a. True False


Question 105.

How do you check if a given number is even in Python?

  • num.even()
  • is_even(num)
  • num % 2 == 0
  • num.is_even()

c. num % 2 == 0


Question 106.

What is the output of the following code?

name = "LogicalPython"
print(name[1:5:2])
  • oi
  • gi
  • oc
  • None of the above

a. oi


Question 107.

What is the output of the following code?

name = "LogicalPython"
print(name[3::-1])
  • igoL
  • Logi
  • noht
  • None of the above

a. igol


Question 108.

What is the output of the following code?

a = 1.0
b = "2"

print(a + b)
  • 1.02
  • 12
  • 3.0
  • TypeError

d. TypeError


Question 109.

What is the output of the following code?

id = 5

def getID():
    id = 8
    print("ID:",id)
    
getID()
print("ID:",id)
  • ID: 8 ID: 5
  • ID: 8 ID: 8
  • ID: 5 ID: 5
  • ID: 5 ID: 8

a. ID: 8 ID: 5


Question 110.

Which of the following is NOT a valid Python variable name?

  • my_var
  • 888_var
  • _var
  • Var007

b. 888_var


Question 111.

How to comment multiple lines in Python?

  • /* sample comment */
  • // sample comment //
  • #sample comment
  • ”’ sample comment ”’

d. ”’ sample comment ”’


Question 112.

What is the output of the following code?

name = "LogicalPython"
print(name[-2:-5])
  • oth
  • othy
  • Error
  • Does not return anything

d. Does not return anything


Question 113.

What is the output of the following code?

dict = {4:'x',5:'y',6:'z'}
print(dict.pop(5))
  • 5
  • y
  • 5:’y’
  • Error

b. y


Question 114.

What is the output of the following code?

x = "Python"
print(x[::-1])
  • Python
  • nohtyP
  • nohty
  • Pyt

b. nohtyP


Question 115.

What is the output of the following code?

x = [1,2,3,4,5]
result = x[1:4:2]
print(result)
  • [2]
  • [2, 4]
  • [2, 3]
  • [1, 3]

b. [2, 4]


Question 116.

How do you check if a given number is odd in Python?

  • num.is_odd()
  • is_odd(num)
  • num % 2 == 1
  • num % 2 == 0

c. num % 2 == 1


Question 117.

How do you get the length of a string?

  • string.len()
  • len(string)
  • string.length()
  • length(string)

b. len(string)


Question 118.

What is the output of the following code?

print(bool(21.21), bool(-21.21), bool(0))
  • True True False
  • False True True
  • True False True
  • None of the above

a. True True False


Question 119.

How to check the number of elements in a list?

  • list.count()
  • list.length()
  • len(list)
  • list.size()

c. len(list)


Question 120.

What is the output of the following code?

print(8/2)
print(8//2)
  • 4 4
  • 4.0 4
  • 4.0 4.0
  • None of the above

Answer:

b. 4.0

Explanation:

  1. print(8/2): This line divides 8 by 2 using the / operator. In Python, the / operator performs normal division, resulting in a floating-point number (a number with a decimal point). So, 8/2 evaluates to 4.0.
  2. print(8//2): This line divides 8 by 2 using the // operator. This is known as integer division or floor division. It divides the two numbers and rounds down to the nearest whole number. So, 8//2 evaluates to 4.

Question 121.

What is the output of the following code?

x = 5
y = 10

x, y = y, x
print(x, y)
  • 5 10
  • 10 5
  • Error
  • None of the above

b. 10 5


Question 122.

Which statement will not print string “it’s” ?

  • str = “it’s”
  • str = ‘it\’s’
  • str = ”’it’s”’
  • str = ‘it\’s’

d. str = ‘it\’s’


Question 123.

What is the output of the following code?

print(type([]) is list, type([]) == list)
  • True True
  • True False
  • False True
  • False False

Answer:

a. True True

Explanation:

  1. type([]) is list : This checks whether the type of an empty list ([]) is identical to the type list. The ‘is’ operator checks for identity, meaning it checks whether the objects on both sides of the operator refer to the same object in memory. Since both sides are indeed referring to the same type (i.e., the type list), this comparison will return True.
  2. type([]) == list : This checks whether the type of an empty list ([]) is equal to the type list. The ‘==’ operator checks for equality, meaning it checks whether the values of the objects on both sides of the operator are the same. Since both sides refer to the same type (list), this comparison will also return True.


Question 124.

What is the output of the following code?

print(9%3, 3%9)
  • 0 3
  • 3 0
  • 0 0
  • 3 0

a. 0 3


Question 125.

What is the output of the following code?

print(10+10*10)
  • 200
  • 100
  • 110
  • 210

c. 110


Question 126.

What does the “elif” keyword mean in Python?

  • It is used to start a new loop.
  • It is a shorthand for “else if.”
  • It is used to handle exceptions.
  • It is used to define a new function.

b. It is a shorthand for “else if.”


Question 127.

What is the output of the following code?

print(2*3**2)
  • 18
  • 36
  • 9
  • 16

a. 18


Question 128.

What is the output of the following code?

def bonus():
    salary = 5000
    return salary

bonus()
print(salary)
  • 5000
  • 2000
  • Error
  • None of the above

c. Error


Question 129.

How to convert a string to an integer?

  • 28.to_int()
  • int(“28”)
  • str(28)
  • 28.cast(int)

b. int(“28”)


Question 130.

What is the output of the following code?

x = 20
x+=10

print(x)
  • 20
  • 10
  • 30
  • 30.0

b. 30


Question 131.

What is the output of the following code?

print(-8 // 3)
  • -3
  • -2
  • 3
  • 2

a. -3


Question 132.

What is the output of the following code?

print(-8 // -3)
  • 3
  • 2
  • -3
  • -2

b. 2


Question 133.

What is the output of the following code?

numbers = [1,2,3]
print(sum(numbers, 50))
  • 50
  • 56
  • 6
  • None of the above

Answer:

b. 56

Explanation:

sum(numbers, 50): This line calls the sum() function, which calculates the sum of all elements in the iterable passed as the first argument. Additionally, it takes an optional second argument, which is the start value for the sum. In this case, the iterable is numbers, and the start value is 50. So the answer is 56.


Question 134.

What is the output of the following code?

x = [1,2]
y = x

y+=[3,4]
print(x)
  • [1, 2, 3, 4]
  • [1, 2]
  • [3, 4]
  • None of the above.

a. [1, 2, 3, 4]


Question 135.

What is the output of the following code?

print(type(range(1)))
  • <class ‘range’>
  • <class ‘int’>
  • Error
  • None of the above.

a. <class ‘range’>


Question 136.

What is the output of the following code?

print(2 ** 3 ** 2)
  • 36
  • 512
  • 64
  • None of the above.

b. 512


Question 137.

How to check if a key exists in a Python dictionary?

  • if key in dict.keys():
  • if dict.contains(key):
  • if key in dict:
  • if dict.get(key) is not None:

c. if key in dict:


Question 138.

What is the output of the following code?

x = [1,2,3,4,5]
result = x[::2]

print(result)
  • [1, 3, 5]
  • [1, 2, 3, 4, 5]
  • [2, 4]
  • [2, 4, 1]

Answer:

a. [1, 3, 5]

Explanation:

result = x[::2]: This creates a new list named result by slicing the list x.

  1. The first colon : indicates that you want to slice the entire list.
  2. The ::2 specifies the step value as 2. This means that Python will take every second element from the original list.

Question 139.

What is the output of the following code?

x = [1,2,3]
y = [4,5]

result = x + y
print(result)
  • [1, 2, 3, 4, 5]
  • [[1, 2, 3], [4, 5]]
  • [1, 2, 3, [4, 5]]
  • [4, 5, 1, 2, 3]

a. [1, 2, 3, 4, 5]


Question 140.

How to remove leading and trailing whitespaces from a string?

  • str.remove()
  • str.clean()
  • str.strip()
  • str.trim()

c. str.strip()


Question 141.

What is the output of the following code?

x = [1,2,3]
y = x.copy()

x.append(4)
print(y)
  • [1, 2, 3]
  • [1, 2, 3, 4]
  • [4, 1, 2, 3]
  • [1, 2, 3, 1]

a. [1, 2, 3]


Question 142.

What statement should be added in the function so that the output is 5?

x = 2
def fun1():
    # new statement
    x = 5
    
fun1()
print(x) # it should be print 5
  • global x
  • local x
  • global x = 5
  • None of the above.

a. global x


Question 143.

What is the output of the following code?

x = [1,2,3]
y = x

y[0] = 10
print(x)
  • [1, 2, 3]
  • [10, 2, 3]
  • [1, 2, 3, 10]
  • [1, 2, 10]

b. [10, 2, 3]


Question 144.

What is the output of the following code?

a = 1
b = 2

_ = a + b
print(_)
  • 3
  • 2
  • _
  • None of the above

Answer:

a. 3

Explanation:

In python, “_” is treated as the normal variable. So it is just holding the sum of variable a and b, i.e. 1 and 2.


Question 145.

What is the output of the following code?

name = "Musk"
print(name[20:1:-1])
  • ksu
  • ks
  • Error
  • No Output

Answer:

b. ks

Explanation:

print(name[20:1:-1]): This line prints a portion of the string stored in the variable name. Check below for the breakdown:

  1. 20: This is the start index of the slice. However, since there is no character at index 20 in the string “Musk”, Python will start from the end of the string and count backwards. So, it starts from the last character “k”.
  2. 1: This is the end index of the slice. However, since slicing in Python excludes the end index, it will stop just before reaching the character at index 1. So, it will stop at index 2, which corresponds to the character “s”.
  3. -1: This is the step value for the slice. It indicates that the slice should move backward through the string, from the start index towards the end index.

Therefore, the final Answer is ks.


Question 146.

What is the output of the following code?

name = "radar "
print(name.replace('a','e',3))
  • reder
  • radar
  • Error
  • None of the above

Answer:

a. reder

Explanation:

  1. The replace() method in Python is used to replace occurrences of a specified substring or character within a string with another substring or character.
  2. In this case, ‘a’ is being replaced with ‘e’.
  3. The 3 as the third argument in the replace() method signifies that only the first 3 occurrences of ‘a’ will be replaced. If there were more occurrences of ‘a’ in the string, they would not be replaced by ‘e’.
  4. So it replaced all two occurrences of a.

Question 147.

What is the output of the following code?

marks = dict(Elon=85, Bill=82, Jeff="84")
print(marks)
  • {‘Elon’: 85, ‘Bill’: 82, ‘Jeff’: 84}
  • {‘Elon’: 85, ‘Bill’: 82, ‘Jeff’: ’84’}
  • {(‘Elon’, 85), (‘Bill’, 82), (‘Jeff’, 84)}
  • None of the above

b. {‘Elon’: 85, ‘Bill’: 82, ‘Jeff’: ’84’}


Question 148.

What is the output of the following code?

name = "radar "
print(name.split('a'))
  • [‘r’, ‘d’, ‘r’]
  • [‘r’, ‘d’]
  • [‘r’, ‘dar’]
  • None of the above

a. [‘r’, ‘d’, ‘r ‘]


Question 149.

What is the output of the following code?

def func():
        print("Hello Logical ", end="")

x = func()
print(x)
  • Hello Logical None
  • Hello Logical
  • Blank
  • Error

a. Hello Logical None