wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz - Till Basic String

Total questions: 100

Worksheet time: 50mins

Name
Class
Date
1.
What is the boolean value of expression: (5 > 3)?
a)
True
b)
False
c)
1
d)
0
2.
Which of these is a valid 'for' loop header in Python?
a)
for i in range(3):
b)
for(i=0;i<3;i++):
c)
for i = 0 to 2:
d)
loop i in 3:
3.
Which statement executes when the 'if' condition is false and no 'elif' matches?
a)
else block
b)
finally block
c)
catch block
d)
then block
4.
Which of the following is a Python numeric type?
a)
int
b)
list
c)
set
d)
tuple
5.
Which operator assigns a value to a variable?
a)
==
b)
=
c)
:=
d)
->
6.
Which is valid to check inequality?
a)
!=
b)
<>
c)
!==
7.
Which is the correct 'else if' keyword in Python?
a)
elif
b)
elseif
c)
else if
d)
elsif
8.
Which of these is a unary operator in Python?
a)
-
b)
and
c)
or
9.
What is the value of -5 % 3 in Python?
a)
1
b)
-1
c)
2
d)
-2
10.
What is printed by: print(0 == False)?
a)
True
b)
False
c)
Error
d)
0
11.
Which of these is the correct way to write multiple statements on one line? (not recommended by PEP8)
a)
a=1; b=2
b)
a=1 b=2
c)
a=1, b=2
d)
a=1: b=2
12.
What is the output of: print(3 > 2 > 1)?
a)
True
b)
False
c)
Error
d)
None
13.
What does '//' do when both operands are negative, e.g., -7 // 3?
a)
-3
b)
-2
c)
2
d)
3
14.
What prints: print(4//2 == 2)?
a)
True
b)
False
c)
Error
d)
None
15.
Which numeric type automatically becomes long in Python 3?
a)
int
b)
long
c)
float
d)
complex
16.
What prints: print(3.0 == 3)?
a)
True
b)
False
c)
Error
d)
None
17.
Which of the following is a bitwise operator?
a)
&
b)
and
c)
&&
d)
andalso
18.
What is the output of: print(1 if True else 0)?
a)
1
b)
0
c)
True
d)
False
19.
Which is the correct way to write multi-line expression using parentheses?
a)
a = (1 + 2 + 3 + 4)
b)
a = 1 + 2 + 3 + \n4
c)
a = 1 + 2 + 3 + 4
d)
a = 1 + 2 + 3 + 4
20.
What does PEP stand for?
a)
Python Enhancement Proposal
b)
Python Engineering Practice
c)
Programmer's Enhancement Plan
d)
Performance Enhancement Patch
21.
Which of these operators is evaluated before logical operators?
a)
*
b)
and
c)
or
d)
not
22.
What is the output: print(2 + 3 * 4 - 5)?
a)
9
b)
12
c)
5
d)
7
23.
What is the output of: x = 5 for i in range(3): x += i print(x)
a)
8
b)
9
c)
7
d)
6
24.
What will this print? for i in range(1): print(i) else: print('done')
a)
0 then done
b)
Only 0
c)
Only done
d)
Error
25.
What is the output of: print((True + True) == 2)?
a)
True
b)
False
c)
Error
d)
0
26.
What is output? a = 10 for i in range(2): a = a + i print(a)
a)
11
b)
12
c)
10
d)
13
27.
Which statement about chained comparisons is true in Python?
a)
They are evaluated left-to-right and can short-circuit
b)
They always return booleans only
c)
They are evaluated as separate boolean operations then combined
d)
They are unsupported
28.
What is the output: print(7 // -3)?
a)
-3
b)
-2
c)
2
d)
3
29.
What does PEP8 recommend about maximum line length for code?
a)
79 characters
b)
120 characters
c)
100 characters
d)
60 characters
30.
Which of these is a valid use of ternary conditional expression?
a)
'yes' if True else 'no'
b)
'yes' if (True)
c)
'yes' unless False
d)
if True: 'yes' else: 'no'
31.
What is printed: print(9 % 4 * 2)?
a)
2
b)
10
c)
1
d)
6
32.
What is the value of (1 + 2) * 3 - 4 / 2 ?
a)
7.0
b)
9.0
c)
6.0
d)
5.0
33.
What will print? for i in range(3): print(i) print('done')
a)
0 1 2 then done
b)
0 1 2 then error
c)
Only done
d)
Error
34.
What is the output of: x = 5 for i in range(3): x += i print(x) (mod var 2)
a)
8
b)
9
c)
7
d)
6
35.
Evaluate: 2 + 3 * 4 ** 2
a)
50
b)
34
c)
38
d)
98
36.
What is the output: for i in range(3): pass else: print('E') print('F')
a)
E then F
b)
Only E
c)
Only F
d)
Error
37.
What prints: print(True == 1 and False == 0)
a)
True
b)
False
c)
Error
d)
None
38.
Which is the result of: 1 or 0 and 0 ?
a)
1
b)
0
c)
False
d)
Error
39.
What is the output of: print((not False) == (False == 0))
a)
True
b)
False
c)
Error
d)
None
40.
What will be printed by: x = 0 for i in range(5): x += i if i == 3: break print(x)
a)
6
b)
3
c)
10
d)
0
41.
What is the result of: (True * 3) + (False + 2)?
a)
5
b)
4
c)
3
d)
6
42.
What will this print? print((1).__add__(2))
a)
3
b)
Error
c)
12
d)
None
43.
What is the result of: (1 << 2) << 1 ?
a)
8
b)
4
c)
2
d)
16
44.
Who created Python programming language?
a)
James Gosling
b)
Guido van Rossum
c)
Dennis Ritchie
d)
Bjarne Stroustrup
45.
Which year was the first public release of Python (version 0.9.0)?
a)
1989
b)
1991
c)
1994
d)
2000
46.
Which symbol starts a single-line comment in Python?
a)
//
b)
#
c)
/*
d)
<!--
47.
What is the output of: 3 + 2 * 2 ?
a)
10
b)
7
c)
8
d)
9
48.
Which operator is used for integer (floor) division in Python?
a)
/
b)
//
c)
%
d)
**
49.
What does the operator '%' return for numbers?
a)
Quotient
b)
Remainder
c)
Power
d)
Floor division
50.
Which keyword starts a conditional block in Python?
a)
when
b)
if
c)
switch
d)
select
51.
PEP 8 is related to which of the following?
a)
Performance tuning
b)
Style guide for Python code
c)
Distribution packaging
d)
Security practices
52.
PEP 20 is better known as?
a)
The Code of Conduct
b)
The Zen of Python
c)
Library reference
d)
Bytecode guide
53.
What is 'associativity' in operator evaluation?
a)
Order of precedence
b)
Direction evaluation when precedence ties
c)
Type conversion rule
d)
Binding power
54.
Which has higher precedence: multiplication or addition?
a)
Addition
b)
Multiplication
c)
They are equal
d)
Depends on operands
55.
What is the output of: 10 % 3 ?
a)
3
b)
1
c)
0
d)
4
56.
Which operator checks equality between two values?
a)
==
b)
=
c)
:=
d)
->
57.
What is the output of: 2 ** 3 ?
a)
6
b)
8
c)
9
d)
5
58.
What will 'print(7//2)' output?
a)
3.5
b)
3
c)
4
d)
2
59.
What is result of: True and False ?
a)
True
b)
False
c)
1
d)
0
60.
What does the expression 'not True' evaluate to?
a)
True
b)
False
c)
1
d)
0
61.
Which of these is true about integer division using '/' in Python 3?
a)
Always returns int
b)
May return float
c)
Performs modulo
d)
Performs bitwise
62.
Which of these is NOT a Python keyword?
a)
pass
b)
eval
c)
yield
d)
global
63.
Which of these is a valid numeric literal in Python?
a)
12
b)
0b101
c)
0xG1
d)
9
64.
Which statement about PEP8 is true?
a)
Mandates use of tabs over spaces
b)
Suggests 79 characters line length
c)
Bans comments
d)
Requires semicolons
65.
What is the output of: print(5 > 2 and 2 > 3)?
a)
True
b)
False
c)
Error
d)
None
66.
Which of these is true about 'is' operator?
a)
Compares values for equality
b)
Compares object identity
c)
Performs assignment
d)
Checks for substring
67.
Which of these indicates a block in Python?
a)
Curly braces {}
b)
Indentation
c)
Semicolon
d)
Parentheses
68.
Who created Python programming language? (easy var 1)
a)
James Gosling
b)
Guido van Rossum
c)
Dennis Ritchie
d)
Bjarne Stroustrup
69.
Which year was the first public release of Python (version 0.9.0)? (easy var 2)
a)
1989
b)
1991
c)
1994
d)
2000
70.
Which of these is true about Python's 'BDFL' status change in 2018?
a)
Guido became BDFL for life
b)
Guido stepped down as BDFL
c)
BDFL concept was introduced in 2018
d)
Python removed PEPs
71.
What is the output of: 4 & 1 ?
a)
5
b)
0
c)
1
d)
4
72.
What does the Zen of Python suggest about 'There should be one—and preferably only one—obvious way to do it'?
a)
Encourages multiple styles
b)
Promotes a single obvious way
c)
Discourages readability
d)
Is about performance
73.
What is the result of: 2**3**2 ?
a)
64
b)
512
c)
256
d)
4096
74.
Which comparison is True: (3 > 2) == (2 < 1)?
a)
True
b)
False
c)
Error
d)
None
75.
What is the output: print( (1 << 3) ) ?
a)
3
b)
8
c)
16
d)
1
76.
What is printed by: print( (5 > 2) and (2 > 5) )?
a)
True
b)
False
c)
None
d)
Error
77.
Which of these best matches 'Readability counts' from Zen of Python?
a)
Favor terse code
b)
Favor readable code
c)
Favor obfuscation
d)
Favor multiple solutions
78.
Which of these comparisons uses identity not equality?
a)
a == b
b)
a is b
c)
a equals b
d)
a := b
79.
What is precedence between 'not' and 'and' operators?
a)
not has lower precedence than and
b)
not has higher precedence than and
c)
equal precedence
d)
depends on operands
80.
What does PEP20 say about 'Namespaces are one honking great idea — let's do more of those'?
a)
Namespaces discouraged
b)
Namespaces encouraged
c)
Namespaces replaced by globals
d)
Only one namespace allowed
81.
Which is true: exponentiation associativity is right-to-left or left-to-right?
a)
Left-to-right
b)
Right-to-left
c)
Depends on Python version
d)
Undefined
82.
Which of these is true about Python's 'BDFL' status change in 2018? (mod var 1)
a)
Guido became BDFL for life
b)
Guido stepped down as BDFL
c)
BDFL concept was introduced in 2018
d)
Python removed PEPs
83.
What does the Zen of Python phrase 'Simple is better than complex' imply for code design?
a)
Choose the most compact code
b)
Prefer simpler clear solutions
c)
Always avoid libraries
d)
Always use functional style
84.
What is the output: a = 2 b = 3 print(a < b == True)
a)
True
b)
False
c)
Error
d)
Depends
85.
Which expression raises SyntaxError?
a)
a = 5
b)
5 = a
c)
a == 5
d)
None of the above
86.
What is the difference between '&' and 'and' when operands are booleans?
a)
They always behave differently
b)
& performs bitwise operation and and is logical; on bools results often same
c)
& will error on bools
d)
and does bitwise
87.
Evaluate: 0.1 + 0.2 == 0.3 in Python?
a)
True
b)
False
c)
Error
d)
Depends on platform
88.
What does PEP 8 recommend about maximum line length historically?
a)
60
b)
79
c)
120
d)
100
89.
Which has higher precedence: '==' or '<<' (left shift)?
a)
= higher
b)
<< higher
c)
equal
d)
Depends
90.
Which of these is correct about operator precedence table?
a)
'**' has lower precedence than '*'
b)
'**' has higher precedence than unary '-'
c)
Comparison operators evaluated before arithmetic
d)
Bitwise ops evaluated before arithmetic
91.
Which expression results in True: float('nan') == float('nan') ?
a)
True
b)
False
c)
Error
d)
Depends
92.
Which of these statements about Python number model is true?
a)
Integers are of fixed size
b)
Integers auto-grow to arbitrary precision
c)
Floats are exact decimal types
d)
There is no complex type
93.
Which of the following is the exponentiation operator in Python?
a)
^
b)
pow
c)
**
d)
exp
94.
Which operator has highest precedence among these?
a)
+
b)
-
c)
*
d)
and
95.
Which naming style for variables is recommended by PEP8?
a)
camelCase
b)
PascalCase
c)
lower_with_underscores
d)
ALLCAPS
96.
Which of these PEP8 rules concerns indentation?
a)
Use 2 spaces per indent
b)
Use tabs only
c)
Use 4 spaces per indentation level
d)
Indentation is optional
97.
Which is true about operator precedence in Python?
a)
Logical ops evaluated before arithmetic
b)
Bitwise ops after comparison
c)
Arithmetic before comparison
d)
Assignment has highest precedence
98.
What is the result of: 0b11 | 0b10 ?
a)
1
b)
2
c)
3
d)
0
99.
What is result of: (3 << 2) + (5 >> 1)?
a)
16
b)
13
c)
14
d)
12
100.
Which expression yields decimal 10?
a)
0b1010
b)
0xA
c)
10
d)
All of the above