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.

Question 10[auto-list-number name = “Quiz”]
What is the output of the following code?
text = 'Logical' * (6//2)
print(text)- LogicalLogicalLogical
- LogicalLogicalLogicalLogicalLogicalLogical
- LogicalLogical
- Error
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. LogicalLogicalLogical
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
d. Error
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
What is the output of the following code?
a = 40 / 10 * (4 + 6) * (6 + 4)
print(a)- 200
- 20
- 400.0
- 40.0
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. 400.0
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. True False
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
How do you check if a given number is even in Python?
- num.even()
- is_even(num)
- num % 2 == 0
- num.is_even()
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. num % 2 == 0
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
What is the output of the following code?
name = "LogicalPython"
print(name[1:5:2])- oi
- gi
- oc
- None of the above
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. oi
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
What is the output of the following code?
name = "LogicalPython"
print(name[3::-1])- igoL
- Logi
- noht
- None of the above
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. igol
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
What is the output of the following code?
a = 1.0
b = "2"
print(a + b)- 1.02
- 12
- 3.0
- TypeError
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
d. TypeError
[/bg_collapse]
Question 10[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. ID: 8 ID: 5
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
Which of the following is NOT a valid Python variable name?
- my_var
- 888_var
- _var
- Var007
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. 888_var
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
How to comment multiple lines in Python?
- /* sample comment */
- // sample comment //
- #sample comment
- ”’ sample comment ”’
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
d. ”’ sample comment ”’
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
name = "LogicalPython"
print(name[-2:-5])- oth
- othy
- Error
- Does not return anything
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
d. Does not return anything
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
dict = {4:'x',5:'y',6:'z'}
print(dict.pop(5))- 5
- y
- 5:’y’
- Error
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. y
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
x = "Python"
print(x[::-1])- Python
- nohtyP
- nohty
- Pyt
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. nohtyP
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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]
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. [2, 4]
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
How do you check if a given number is odd in Python?
- num.is_odd()
- is_odd(num)
- num % 2 == 1
- num % 2 == 0
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. num % 2 == 1
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
How do you get the length of a string?
- string.len()
- len(string)
- string.length()
- length(string)
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. len(string)
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. True True False
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
How to check the number of elements in a list?
- list.count()
- list.length()
- len(list)
- list.size()
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. len(list)
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
Answer:
b. 4.0
Explanation:
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/2evaluates to4.0.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//2evaluates to4.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. 10 5
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
Which statement will not print string “it’s” ?
- str = “it’s”
- str = ‘it\’s’
- str = ”’it’s”’
- str = ‘it\’s’
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
d. str = ‘it\’s’
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(type([]) is list, type([]) == list)- True True
- True False
- False True
- False False
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
Answer:
a. True True
Explanation:
- 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.
- 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.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(9%3, 3%9)- 0 3
- 3 0
- 0 0
- 3 0
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. 0 3
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(10+10*10)- 200
- 100
- 110
- 210
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. 110
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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.
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. It is a shorthand for “else if.”
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(2*3**2)- 18
- 36
- 9
- 16
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. 18
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
def bonus():
salary = 5000
return salary
bonus()
print(salary)- 5000
- 2000
- Error
- None of the above
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. Error
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
How to convert a string to an integer?
- 28.to_int()
- int(“28”)
- str(28)
- 28.cast(int)
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. int(“28”)
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
x = 20
x+=10
print(x)- 20
- 10
- 30
- 30.0
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. 30
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(-8 // 3)- -3
- -2
- 3
- 2
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. -3
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(-8 // -3)- 3
- 2
- -3
- -2
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. 2
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
numbers = [1,2,3]
print(sum(numbers, 50))- 50
- 56
- 6
- None of the above
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
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.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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.
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. [1, 2, 3, 4]
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(type(range(1)))- <class ‘range’>
- <class ‘int’>
- Error
- None of the above.
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. <class ‘range’>
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
print(2 ** 3 ** 2)- 36
- 512
- 64
- None of the above.
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. 512
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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:
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. if key in dict:
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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]
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
Answer:
a. [1, 3, 5]
Explanation:
result = x[::2]: This creates a new list named result by slicing the list x.
- The first colon : indicates that you want to slice the entire list.
- The ::2 specifies the step value as 2. This means that Python will take every second element from the original list.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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]
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. [1, 2, 3, 4, 5]
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
How to remove leading and trailing whitespaces from a string?
- str.remove()
- str.clean()
- str.strip()
- str.trim()
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
c. str.strip()
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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]
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. [1, 2, 3]
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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.
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. global x
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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]
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. [10, 2, 3]
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
a = 1
b = 2
_ = a + b
print(_)- 3
- 2
- _
- None of the above
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
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.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
name = "Musk"
print(name[20:1:-1])- ksu
- ks
- Error
- No Output
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
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:
- 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”.
- 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”.
- -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.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
What is the output of the following code?
name = "radar "
print(name.replace('a','e',3))- reder
- radar
- Error
- None of the above
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
Answer:
a. reder
Explanation:
- The replace() method in Python is used to replace occurrences of a specified substring or character within a string with another substring or character.
- In this case, ‘a’ is being replaced with ‘e’.
- 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’.
- So it replaced all two occurrences of a.
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
b. {‘Elon’: 85, ‘Bill’: 82, ‘Jeff’: ’84’}
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. [‘r’, ‘d’, ‘r ‘]
[/bg_collapse]
Question 1[auto-list-number name = “Quiz”]
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
[bg_collapse view=”button-green” color=”#ffffff” icon=”arrow” expand_text=”Show Answer” collapse_text=”Hide Answer” ]
a. Hello Logical None
[/bg_collapse]