WorksheetsPython Basics MCQ Worksheet
Total questions: 148
Worksheet time: 1hrs 14mins
What is the output of the following code? x = [1, 2, 3] print(x[::-1])
[3, 2, 1]
[1, 2]
Error
[1, 2, 3, -1]
None
Which statement about Python sets is TRUE?
They allow duplicate elements
They maintain insertion order
They are indexed
They are mutable
They allow lists as elements
What is the output? print(bool([]))
True
False
0
None
Error
Which method is used to add an item to a dictionary only if the key does NOT exist?
add()
insert()
update()
setdefault()
append()
What will this code print? x = [1, 2, 3] y = x y += [4] print(x)
[1,2,3]
[1,2,3,4]
Error
[4]
[1, 2]
What is the time complexity of checking key existence in a dictionary?
O(n²)
O(log n)
O(n)
O(1) average case
O(n log n)
What is the output? a = [1, 2, 3] print(a*2)
[1, 2, 3, 1, 2, 3]
[2, 4, 6]
Error
[1,1,2,2,3,3]
None
Which operator is used for floor division?
/
%
//
**
&
What is the output? print(type({}))
Which statement about Python tuples is TRUE?
They are mutable
They can contain duplicate values
They are slower than lists
They cannot contain different data types
They guarantee sorted order
What does enumerate() return?
Only values
Only indices
Index–value pairs
A dictionary
A generator that produces values only
What is the output of the code? print(",".join(["a","b","c"]))
a,b,c
abc
a b c
a,b,c,
Error
Which file opening mode allows reading and writing but truncates the file?
"r+"
"w+"
"a+"
"x"
"t"
What is the output? print(2 < 3 < 4)
SyntaxError
False
True
2
None
What is the data type of this expression? {x for x in range(3)}
List
Generator
Set
Dictionary
Tuple
What does slicing with a step of -1 do?
Removes last item
Rotates list
Reverses sequence
Returns odd-indexed items
Returns even-indexed items
Which is NOT a valid Python data type?
list
map
set
char
tuple
What is the output? print({1,2,3} & {3,4,5})
{1,2,3,4,5}
{3}
{}
Error
{1}
Which string method removes whitespace from BOTH ends?
cut()
remove()
trim()
strip()
clean()
What is the output? print([i for i in range(5) if i % 2 == 0])
[0, 1, 2, 3, 4]
[1, 3]
[0, 2, 4]
[2, 4]
Error
What is the output? a = [1, 2, 3] b = a[:] b.append(4) print(a)
[1, 2, 3, 4]
[1, 2]
[1, 2, 3]
Error
None
What does the zip() function return?
List
Generator-like object
Dictionary
Tuple
Iterator that auto-expands values
What is the output? print({i:i*i for i in range(3)}[2])
{2:4}
4
[4]
2
Error
Which of these opens a file for appending?
"r"
"a"
"w"
"x"
"rw"
What is a correct way to check if a key exists in a dict?
if key exists dict:
if key -> dict:
if key in dict:
if dict[key] != None:
dict.has(key)
What is the output? print((1,2,3) + (4,5))
(1,2,3,4,5)
[1,2,3,4,5]
Error
(5,4,3,2,1)
None
Which method removes and returns the LAST item in a list?
shift()
pop(0)
pop()
remove()
del()
What is the output? print("Python".upper().lower())
"PYTHON"
"python"
"Python"
"PyThOn"
Error
What will be the type of this variable? x = (i for i in range(5))
list
tuple
generator
set
map
What is the result of: print(all([True, 1, "hello"]))
False
True
0
Error
None
Which function returns the Unicode code of a character?
chr()
unicode()
ord()
ascii()
bin()
Which statement about Python classes is TRUE?
Python supports multiple inheritance
Python does NOT support inheritance
Methods must be static
Constructors must be named constructor()
Classes cannot contain functions
What is the output? print(list("abc"))
"abc"
['a', 'b', 'c']
[abc]
['abc']
Error
What will this code output? x = {1,2,3} y = {3,4,5} print(x | y)
{1,2}
{3}
{1,2,3,4,5}
{}
Error
What is the output? for i in range(3): pass print(i)
0
3
2
None
Error
Which module is used for regular expressions?
regex
re
pattern
match
search
What is the output? print("hello".replace("l", "L", 1))
"heLlo"
"heLlo"
"HELLo"
"hELlo"
"hello"
What does __init__ represent?
Destructor
Public variable
Class name
Constructor
Magic static method
Which is NOT a valid list method? method? A. append()
append()
insert()
push()
extend()
sort()
What will this code print? print(len({1: "a", 2: "b", 3: "c"}))
'3'
3
6
1
Error
What is the output? print({1,2,3}.issubset({1,2,3,4}))
False
True
{1,2,3}
{}
Error
What is the output? print(type(range(5)))
Which line correctly defines a lambda?
lambda x: return x*2
x => x*2
def x -> x*2
f = lambda x: x*2
function(x) x*2
What is the output? x = [1,2,3,4] print(x[1:3])
[1,2,3]
[2,3]
[3,4]
[1,3]
Error
What will this print? print(min([5, 2, 9, 1]))
9
5
2
1
Error
What is the output? print(bool(" "))
False
True
None
0
Error
The expression 3∗∗2 means:
3 multiplied by 2
3 divided by 2
3 to the power of 2
bitwise XOR
modulo operation
What is the output? a = (1,2,3) b = (4,) print(a + b)
(5,5,5)
(1,2,3,4)
(1,2,3,(4,))
Error
[1,2,3,4]
Which method converts an object to a string?
__string__()
__str__()
__to_string__()
__repr__()
toStr()
What is the output? print({1,2,2,3})
{1,2,2,3}
[1,2,3]
{1,2,3}
(1,2,3)
Error
Which keyword is used to handle exceptions?
throw
except
handle
catch
fault
What does this code output? print("hello".find("l"))
-1
1
2
3
Error
What is the output? x = {"a":1, "b":2} print(list(x.keys()))
["a","b"]
["b","a"]
["a"]
("a","b")
{"a","b"}
Which method removes ALL items from a list?
remove()
delete()
discard()
clear()
reset()
What is the output? print(sum([1,2,3,4]))
10
24
8
12
Error
What is the output? print(type(()))
Error
Which operator checks if two variables point to the same object?
==
!=
is
===
<>
What is the output? x = [1,2,3] print(2 in x)
"True"
False
True
2
Error
What is printed? print(len((1, [2,3], 4)))
3
2
4
Error
1
What is the output? print({}.get("x", 5))
"x"
{}
5
None
Error
What is the output? d = {"a": 1, "b": 2} print("c" in d)
True
False
"c"
Error
None
Which module is used to work with JSON data?
pickle
json
csv
os
struct
What is the output? print([i*i for i in range(3)])
[1,2,3]
[1,4,9]
[0,1,4]
[0,1,2]
Error
What happens if you call int("10.5")?
Returns 10
Returns 10.5
Error
Returns "10"
Returns "10.5"
Which operator concatenates strings?
&
*
+
%
.
What is the output? x = [1,2,3] x.insert(0, 10) print(x)
[10,1,2,3]
[1,2,3,10]
[1,10,2,3]
Error
[0,1,2,3,10]
What does this return? len("hello world".split())
11
2
1
5
"hello world"
What is the output? print(type(lambda x: x**2))
Error
What is the output? print(bool({}))
True
False
{}
Error
None
What is the output? print(list(range(2, 10, 3)))
[2,3,4,5,6,7,8,9]
[2,5,8]
[3,6,9]
[2,10]
Error
What method removes an item by VALUE from a list?
pop()
delete()
remove()
clear()
extract()
What is the output? print(any([0, False, 5]))
False
True
5
Error
None
Which expression creates an empty set?
{}
set()
[]
()
emptyset()
Which function is used to read command-line arguments?
sys.args
args.sys
sys.argv
argv.sys
command.line()
What is the output? x = {"a":1, "b":2} x["a"] = 10 print(x["a"])
1
10
"a"
Error
None
Which built-in function returns the absolute value?
abs()
absolute()
fabs()
math.abs()
value()
What will be printed? print([1,2,3][::-1][0])
1
2
3
Error
[3,2,1]
Which keyword stops a loop early?
stop
skip
end
break
continue
Which property controls the text color?
font-color
text-style
color
foreground
Which CSS unit is relative to the root font size?
em
rem
px
%
What does display: flex; do?
Adds animation
Creates a flex container
Sets text alignment
Changes color
Which property sets the background image?
background-img
bg-image
background-image
image-bg
Which value makes an element disappear but keep its space?
none
hidden
collapse
invisible
Which property changes the font size?
font-size
size-font
text-size
font-weight
Which selector targets elements by ID?
.idname
#idname
id(idname)
@idname
Which property sets the line spacing?
line-height
letter-spacing
spacing
text-spacing
Which keyword is used to make a property inherit from its parent?
parent
default
inherit
extend
Which pseudo-class selects hovered elements?
:hover
:onhover
::hover
:mouse
Which property controls element stacking order?
index
z-index
stack
position-index
Which property sets internal spacing of an element?
margin
padding
indent
spacing
Which property defines border width, style, and color in one?
border-all
border
outline
frame
How do you import another stylesheet?
@css
import-css
@import
include
Which value makes an element a block-level element?
block
inline
flex
relative
Which CSS feature allows different styles for screen sizes?
adaptors
media queries
conditions
breakpoints
Which property rounds the corners?
border-round
corner-radius
border-radius
round
Which selector selects direct child elements?
A + B
A B
A > B
A ~ B
Which property controls transparency?
opacity
alpha
filter
visibility
Which property sets bold text?
font-style
font-weight
weight
boldness
Which property sets spacing between letters?
line-height
word-spacing
letter-spacing
text-spacing
Which CSS layout module aligns items on a grid?
Flexbox
Box
Grid
Table
What is the default display for ?
block
inline
flex
grid
Which property is used to make text italic?
font-italic
text-italic
font-style
italicize
Which function defines a variable?
var()
get()
cssvar()
value()
What is position: absolute; relative to?
viewport
nearest positioned ancestor
body
root element
Which property controls the space outside an element?
border
margin
padding
offset
Which shorthand sets margin values?
margin
margin-size
margin-set
margin-group
Which property sets shadow behind elements?
element-shadow
shadow
box-shadow
drop-shadow
Which CSS function blends colors?
mix()
color-mix()
blend()
rgba-blend()
Which property sets text underline?
text-decoration
underline
text-under
decoration
Which unit is relative to viewport width?
vw
vh
vmin
vmax
Which property sets animation speed?
animation-length
transition-time
animation-duration
Which property positions elements in a grid column?
grid-col
column
grid-column
col-span
Which selector selects all elements?
all
*
universal
any
Which property hides overflowing content?
hide
overflow
invisible
content-hide
What does flex-direction: column; do?
Aligns items horizontally
Reverses order
Aligns items vertically
Wraps items
Which property specifies font family?
font-name
font
font-family
typeface
Which selector selects attributes?
E[attr="value"]
E#value
E.attr
E(value)
Which property controls element width?
block-size
width
inline-size
size
Which property enables smooth transitions?
animate
transition
speed
duration
Which property sets spacing between words?
letter-spacing
word-spacing
line-height
text-spacing
Which keyword prevents element wrapping in flexbox?
nowrap
no-wrap
disable-wrap
stop-wrap
Which value makes background repeat only horizontally?
repeat
repeat-y
repeat-x
no-repeat
Which property sets the outline around an element?
border
outline
stroke
frame
Which property sets max width?
max
max-width
limit-width
width-limit
Which unit is scalable with container font size?
rem
px
em
%
Which property changes cursor appearance?
pointer
cursor
mouse
cursor-style
Which value aligns text to both edges?
left
center
right
justify
Which property controls grid gaps?
grid-gap
gap
grid-spacing
spacing
Which property sets a CSS transition’s delay?
transition-wait
delay
transition-delay
animation-delay
Which selector selects the first child?
:first
:first-child
::first
:first-element
Which property makes an element sticky while scrolling?
fixed
absolute
sticky
scroll
Which function rotates an element?
rotate()
transform-rotate()
rotation()
transform()
Which property sets flex item growth?
grow
flex-grow
item-grow
flex-size
Which property sets background size?
bg-size
size
background-size
img-size
Which property defines grid template areas?
grid-template
template-area
grid-area
grid-template-areas
Which pseudoelement targets the first letter?
:first-letter
::first-letter
:letter-first
::letter
Which property adds space between columns?
column-space
column-gap
gap
col-gap
Which property applies a blur effect?
blur
filter: blur()
backdrop
transform-blur
Which position keeps element fixed to viewport?
relative
static
absolute
fixed
Which property sets transition timing function?
timing
transition-function
transition-timing-function
animation-speed
Which value stacks flex items vertically?
row
column
stack
vertical
Which property sets border style?
border
border-outline
border-style
b-style
Which function converts HSL colors?
hsl()
hsl-color()
color-hsl()
hsl-func()
Which shorthand sets font properties?
font
font-all
font-set
type
Which pseudoclass selects checked checkboxes?
:select
:checked
:active
:toggled
Which property sets CSS grid rows?
grid-rows
rows
grid-template-rows
row-template
Which value makes flex items wrap?
wrap
nowrap
wrap-items
auto-wrap
Which property controls overflow scrollbars?
scroll
overflow
scrollbars
overflow-style
