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 101.
What is the output of the following code?
text = 'Logical' * (6//2)
print(text)
- LogicalLogicalLogical
- LogicalLogicalLogicalLogicalLogicalLogical
- LogicalLogical
- Error
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
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
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
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()
Question 106.
What is the output of the following code?
name = "LogicalPython"
print(name[1:5:2])
- oi
- gi
- oc
- None of the above
Question 107.
What is the output of the following code?
name = "LogicalPython"
print(name[3::-1])
- igoL
- Logi
- noht
- None of the above
Question 108.
What is the output of the following code?
a = 1.0
b = "2"
print(a + b)
- 1.02
- 12
- 3.0
- 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
Question 110.
Which of the following is NOT a valid Python variable name?
- my_var
- 888_var
- _var
- Var007
Question 111.
How to comment multiple lines in Python?
- /* sample comment */
- // sample comment //
- #sample comment
- ”’ 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
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
Question 114.
What is the output of the following code?
x = "Python"
print(x[::-1])
- Python
- nohtyP
- nohty
- Pyt
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]
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
Question 117.
How do you get the length of a string?
- string.len()
- len(string)
- string.length()
- length(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
Question 119.
How to check the number of elements in a list?
- list.count()
- list.length()
- len(list)
- list.size()
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
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
Question 122.
Which statement will not print string “it’s” ?
- str = “it’s”
- str = ‘it\’s’
- str = ”’it’s”’
- 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
Question 124.
What is the output of the following code?
print(9%3, 3%9)
- 0 3
- 3 0
- 0 0
- 3 0
Question 125.
What is the output of the following code?
print(10+10*10)
- 200
- 100
- 110
- 210
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.
Question 127.
What is the output of the following code?
print(2*3**2)
- 18
- 36
- 9
- 16
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
Question 129.
How to convert a string to an integer?
- 28.to_int()
- int(“28”)
- str(28)
- 28.cast(int)
Question 130.
What is the output of the following code?
x = 20
x+=10
print(x)
- 20
- 10
- 30
- 30.0
Question 131.
What is the output of the following code?
print(-8 // 3)
- -3
- -2
- 3
- 2
Question 132.
What is the output of the following code?
print(-8 // -3)
- 3
- 2
- -3
- -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
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.
Question 135.
What is the output of the following code?
print(type(range(1)))
- <class ‘range’>
- <class ‘int’>
- Error
- None of the above.
Question 136.
What is the output of the following code?
print(2 ** 3 ** 2)
- 36
- 512
- 64
- None of the above.
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:
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]
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]
Question 140.
How to remove leading and trailing whitespaces from a string?
- str.remove()
- str.clean()
- str.strip()
- str.trim()
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]
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.
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]
Question 144.
What is the output of the following code?
a = 1
b = 2
_ = a + b
print(_)
- 3
- 2
- _
- None of the above
Question 145.
What is the output of the following code?
name = "Musk"
print(name[20:1:-1])
- ksu
- ks
- Error
- No Output
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
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
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
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