Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics MCQ Worksheet

Total questions: 148

Worksheet time: 1hrs 14mins

Name
Class
Date
1.

What is the output of the following code? x = [1, 2, 3] print(x[::-1])

a)

[3, 2, 1]

b)

[1, 2]

c)

Error

d)

[1, 2, 3, -1]

e)

None

2.

Which statement about Python sets is TRUE?

a)

They allow duplicate elements

b)

They maintain insertion order

c)

They are indexed

d)

They are mutable

e)

They allow lists as elements

3.

What is the output? print(bool([]))

a)

True

b)

False

c)

0

d)

None

e)

Error

4.

Which method is used to add an item to a dictionary only if the key does NOT exist?

a)

add()

b)

insert()

c)

update()

d)

setdefault()

e)

append()

5.

What will this code print? x = [1, 2, 3] y = x y += [4] print(x)

a)

[1,2,3]

b)

[1,2,3,4]

c)

Error

d)

[4]

e)

[1, 2]

6.

What is the time complexity of checking key existence in a dictionary?

a)

O(n²)

b)

O(log n)

c)

O(n)

d)

O(1) average case

e)

O(n log n)

7.

What is the output? a = [1, 2, 3] print(a*2)

a)

[1, 2, 3, 1, 2, 3]

b)

[2, 4, 6]

c)

Error

d)

[1,1,2,2,3,3]

e)

None

8.

Which operator is used for floor division?

a)

/

b)

%

c)

//

d)

**

e)

&

9.

What is the output? print(type({}))

a)

b)

c)

d)

10.

Which statement about Python tuples is TRUE?

a)

They are mutable

b)

They can contain duplicate values

c)

They are slower than lists

d)

They cannot contain different data types

e)

They guarantee sorted order

11.

What does enumerate() return?

a)

Only values

b)

Only indices

c)

Index–value pairs

d)

A dictionary

e)

A generator that produces values only

12.

What is the output of the code? print(",".join(["a","b","c"]))

a)

a,b,c

b)

abc

c)

a b c

d)

a,b,c,

e)

Error

13.

Which file opening mode allows reading and writing but truncates the file?

a)

"r+"

b)

"w+"

c)

"a+"

d)

"x"

e)

"t"

14.

What is the output? print(2 < 3 < 4)

a)

SyntaxError

b)

False

c)

True

d)

2

e)

None

15.

What is the data type of this expression? {x for x in range(3)}

a)

List

b)

Generator

c)

Set

d)

Dictionary

e)

Tuple

16.

What does slicing with a step of -1 do?

a)

Removes last item

b)

Rotates list

c)

Reverses sequence

d)

Returns odd-indexed items

e)

Returns even-indexed items

17.

Which is NOT a valid Python data type?

a)

list

b)

map

c)

set

d)

char

e)

tuple

18.

What is the output? print({1,2,3} & {3,4,5})

a)

{1,2,3,4,5}

b)

{3}

c)

{}

d)

Error

e)

{1}

19.

Which string method removes whitespace from BOTH ends?

a)

cut()

b)

remove()

c)

trim()

d)

strip()

e)

clean()

20.

What is the output? print([i for i in range(5) if i % 2 == 0])

a)

[0, 1, 2, 3, 4]

b)

[1, 3]

c)

[0, 2, 4]

d)

[2, 4]

e)

Error

21.

What is the output? a = [1, 2, 3] b = a[:] b.append(4) print(a)

a)

[1, 2, 3, 4]

b)

[1, 2]

c)

[1, 2, 3]

d)

Error

e)

None

22.

What does the zip() function return?

a)

List

b)

Generator-like object

c)

Dictionary

d)

Tuple

e)

Iterator that auto-expands values

23.

What is the output? print({i:i*i for i in range(3)}[2])

a)

{2:4}

b)

4

c)

[4]

d)

2

e)

Error

24.

Which of these opens a file for appending?

a)

"r"

b)

"a"

c)

"w"

d)

"x"

e)

"rw"

25.

What is a correct way to check if a key exists in a dict?

a)

if key exists dict:

b)

if key -> dict:

c)

if key in dict:

d)

if dict[key] != None:

e)

dict.has(key)

26.

What is the output? print((1,2,3) + (4,5))

a)

(1,2,3,4,5)

b)

[1,2,3,4,5]

c)

Error

d)

(5,4,3,2,1)

e)

None

27.

Which method removes and returns the LAST item in a list?

a)

shift()

b)

pop(0)

c)

pop()

d)

remove()

e)

del()

28.

What is the output? print("Python".upper().lower())

a)

"PYTHON"

b)

"python"

c)

"Python"

d)

"PyThOn"

e)

Error

29.

What will be the type of this variable? x = (i for i in range(5))

a)

list

b)

tuple

c)

generator

d)

set

e)

map

30.

What is the result of: print(all([True, 1, "hello"]))

a)

False

b)

True

c)

0

d)

Error

e)

None

31.

Which function returns the Unicode code of a character?

a)

chr()

b)

unicode()

c)

ord()

d)

ascii()

e)

bin()

32.

Which statement about Python classes is TRUE?

a)

Python supports multiple inheritance

b)

Python does NOT support inheritance

c)

Methods must be static

d)

Constructors must be named constructor()

e)

Classes cannot contain functions

33.

What is the output? print(list("abc"))

a)

"abc"

b)

['a', 'b', 'c']

c)

[abc]

d)

['abc']

e)

Error

34.

What will this code output? x = {1,2,3} y = {3,4,5} print(x | y)

a)

{1,2}

b)

{3}

c)

{1,2,3,4,5}

d)

{}

e)

Error

35.

What is the output? for i in range(3): pass print(i)

a)

0

b)

3

c)

2

d)

None

e)

Error

36.

Which module is used for regular expressions?

a)

regex

b)

re

c)

pattern

d)

match

e)

search

37.

What is the output? print("hello".replace("l", "L", 1))

a)

"heLlo"

b)

"heLlo"

c)

"HELLo"

d)

"hELlo"

e)

"hello"

38.

What does __init__ represent?

a)

Destructor

b)

Public variable

c)

Class name

d)

Constructor

e)

Magic static method

39.

Which is NOT a valid list method? method? A. append()

a)

append()

b)

insert()

c)

push()

d)

extend()

e)

sort()

40.

What will this code print? print(len({1: "a", 2: "b", 3: "c"}))

a)

'3'

b)

3

c)

6

d)

1

e)

Error

41.

What is the output? print({1,2,3}.issubset({1,2,3,4}))

a)

False

b)

True

c)

{1,2,3}

d)

{}

e)

Error

42.

What is the output? print(type(range(5)))

a)

b)

c)

43.

Which line correctly defines a lambda?

a)

lambda x: return x*2

b)

x => x*2

c)

def x -> x*2

d)

f = lambda x: x*2

e)

function(x) x*2

44.

What is the output? x = [1,2,3,4] print(x[1:3])

a)

[1,2,3]

b)

[2,3]

c)

[3,4]

d)

[1,3]

e)

Error

45.

What will this print? print(min([5, 2, 9, 1]))

a)

9

b)

5

c)

2

d)

1

e)

Error

46.

What is the output? print(bool(" "))

a)

False

b)

True

c)

None

d)

0

e)

Error

47.

The expression 3∗∗23 ** 2 means:

a)

3 multiplied by 2

b)

3 divided by 2

c)

3 to the power of 2

d)

bitwise XOR

e)

modulo operation

48.

What is the output? a = (1,2,3) b = (4,) print(a + b)

a)

(5,5,5)

b)

(1,2,3,4)

c)

(1,2,3,(4,))

d)

Error

e)

[1,2,3,4]

49.

Which method converts an object to a string?

a)

__string__()

b)

__str__()

c)

__to_string__()

d)

__repr__()

e)

toStr()

50.

What is the output? print({1,2,2,3})

a)

{1,2,2,3}

b)

[1,2,3]

c)

{1,2,3}

d)

(1,2,3)

e)

Error

51.

Which keyword is used to handle exceptions?

a)

throw

b)

except

c)

handle

d)

catch

e)

fault

52.

What does this code output? print("hello".find("l"))

a)

-1

b)

1

c)

2

d)

3

e)

Error

53.

What is the output? x = {"a":1, "b":2} print(list(x.keys()))

a)

["a","b"]

b)

["b","a"]

c)

["a"]

d)

("a","b")

e)

{"a","b"}

54.

Which method removes ALL items from a list?

a)

remove()

b)

delete()

c)

discard()

d)

clear()

e)

reset()

55.

What is the output? print(sum([1,2,3,4]))

a)

10

b)

24

c)

8

d)

12

e)

Error

56.

What is the output? print(type(()))

a)

b)

c)

d)

e)

Error

57.

Which operator checks if two variables point to the same object?

a)

==

b)

!=

c)

is

d)

===

e)

<>

58.

What is the output? x = [1,2,3] print(2 in x)

a)

"True"

b)

False

c)

True

d)

2

e)

Error

59.

What is printed? print(len((1, [2,3], 4)))

a)

3

b)

2

c)

4

d)

Error

e)

1

60.

What is the output? print({}.get("x", 5))

a)

"x"

b)

{}

c)

5

d)

None

e)

Error

61.

What is the output? d = {"a": 1, "b": 2} print("c" in d)

a)

True

b)

False

c)

"c"

d)

Error

e)

None

62.

Which module is used to work with JSON data?

a)

pickle

b)

json

c)

csv

d)

os

e)

struct

63.

What is the output? print([i*i for i in range(3)])

a)

[1,2,3]

b)

[1,4,9]

c)

[0,1,4]

d)

[0,1,2]

e)

Error

64.

What happens if you call int("10.5")?

a)

Returns 10

b)

Returns 10.5

c)

Error

d)

Returns "10"

e)

Returns "10.5"

65.

Which operator concatenates strings?

a)

&

b)

*

c)

+

d)

%

e)

.

66.

What is the output? x = [1,2,3] x.insert(0, 10) print(x)

a)

[10,1,2,3]

b)

[1,2,3,10]

c)

[1,10,2,3]

d)

Error

e)

[0,1,2,3,10]

67.

What does this return? len("hello world".split())

a)

11

b)

2

c)

1

d)

5

e)

"hello world"

68.

What is the output? print(type(lambda x: x**2))

a)

b)

c)

d)

Error

e)

69.

What is the output? print(bool({}))

a)

True

b)

False

c)

{}

d)

Error

e)

None

70.

What is the output? print(list(range(2, 10, 3)))

a)

[2,3,4,5,6,7,8,9]

b)

[2,5,8]

c)

[3,6,9]

d)

[2,10]

e)

Error

71.

What method removes an item by VALUE from a list?

a)

pop()

b)

delete()

c)

remove()

d)

clear()

e)

extract()

72.

What is the output? print(any([0, False, 5]))

a)

False

b)

True

c)

5

d)

Error

e)

None

73.

Which expression creates an empty set?

a)

{}

b)

set()

c)

[]

d)

()

e)

emptyset()

74.

Which function is used to read command-line arguments?

a)

sys.args

b)

args.sys

c)

sys.argv

d)

argv.sys

e)

command.line()

75.

What is the output? x = {"a":1, "b":2} x["a"] = 10 print(x["a"])

a)

1

b)

10

c)

"a"

d)

Error

e)

None

76.

Which built-in function returns the absolute value?

a)

abs()

b)

absolute()

c)

fabs()

d)

math.abs()

e)

value()

77.

What will be printed? print([1,2,3][::-1][0])

a)

1

b)

2

c)

3

d)

Error

e)

[3,2,1]

78.

Which keyword stops a loop early?

a)

stop

b)

skip

c)

end

d)

break

e)

continue

79.

Which property controls the text color?

a)

font-color

b)

text-style

c)

color

d)

foreground

80.

Which CSS unit is relative to the root font size?

a)

em

b)

rem

c)

px

d)

%

81.

What does display: flex; do?

a)

Adds animation

b)

Creates a flex container

c)

Sets text alignment

d)

Changes color

82.

Which property sets the background image?

a)

background-img

b)

bg-image

c)

background-image

d)

image-bg

83.

Which value makes an element disappear but keep its space?

a)

none

b)

hidden

c)

collapse

d)

invisible

84.

Which property changes the font size?

a)

font-size

b)

size-font

c)

text-size

d)

font-weight

85.

Which selector targets elements by ID?

a)

.idname

b)

#idname

c)

id(idname)

d)

@idname

86.

Which property sets the line spacing?

a)

line-height

b)

letter-spacing

c)

spacing

d)

text-spacing

87.

Which keyword is used to make a property inherit from its parent?

a)

parent

b)

default

c)

inherit

d)

extend

88.

Which pseudo-class selects hovered elements?

a)

:hover

b)

:onhover

c)

::hover

d)

:mouse

89.

Which property controls element stacking order?

a)

index

b)

z-index

c)

stack

d)

position-index

90.

Which property sets internal spacing of an element?

a)

margin

b)

padding

c)

indent

d)

spacing

91.

Which property defines border width, style, and color in one?

a)

border-all

b)

border

c)

outline

d)

frame

92.

How do you import another stylesheet?

a)

@css

b)

import-css

c)

@import

d)

include

93.

Which value makes an element a block-level element?

a)

block

b)

inline

c)

flex

d)

relative

94.

Which CSS feature allows different styles for screen sizes?

a)

adaptors

b)

media queries

c)

conditions

d)

breakpoints

95.

Which property rounds the corners?

a)

border-round

b)

corner-radius

c)

border-radius

d)

round

96.

Which selector selects direct child elements?

a)

A + B

b)

A B

c)

A > B

d)

A ~ B

97.

Which property controls transparency?

a)

opacity

b)

alpha

c)

filter

d)

visibility

98.

Which property sets bold text?

a)

font-style

b)

font-weight

c)

weight

d)

boldness

99.

Which property sets spacing between letters?

a)

line-height

b)

word-spacing

c)

letter-spacing

d)

text-spacing

100.

Which CSS layout module aligns items on a grid?

a)

Flexbox

b)

Box

c)

Grid

d)

Table

101.

What is the default display for ?

a)

block

b)

inline

c)

flex

d)

grid

102.

Which property is used to make text italic?

a)

font-italic

b)

text-italic

c)

font-style

d)

italicize

103.

Which function defines a variable?

a)

var()

b)

get()

c)

cssvar()

d)

value()

104.

What is position: absolute; relative to?

a)

viewport

b)

nearest positioned ancestor

c)

body

d)

root element

105.

Which property controls the space outside an element?

a)

border

b)

margin

c)

padding

d)

offset

106.

Which shorthand sets margin values?

a)

margin

b)

margin-size

c)

margin-set

d)

margin-group

107.

Which property sets shadow behind elements?

a)

element-shadow

b)

shadow

c)

box-shadow

d)

drop-shadow

108.

Which CSS function blends colors?

a)

mix()

b)

color-mix()

c)

blend()

d)

rgba-blend()

109.

Which property sets text underline?

a)

text-decoration

b)

underline

c)

text-under

d)

decoration

110.

Which unit is relative to viewport width?

a)

vw

b)

vh

c)

vmin

d)

vmax

111.

Which property sets animation speed?

a)

animation-length

b)

transition-time

c)

animation-duration

112.

Which property positions elements in a grid column?

a)

grid-col

b)

column

c)

grid-column

d)

col-span

113.

Which selector selects all elements?

a)

all

b)

*

c)

universal

d)

any

114.

Which property hides overflowing content?

a)

hide

b)

overflow

c)

invisible

d)

content-hide

115.

What does flex-direction: column; do?

a)

Aligns items horizontally

b)

Reverses order

c)

Aligns items vertically

d)

Wraps items

116.

Which property specifies font family?

a)

font-name

b)

font

c)

font-family

d)

typeface

117.

Which selector selects attributes?

a)

E[attr="value"]

b)

E#value

c)

E.attr

d)

E(value)

118.

Which property controls element width?

a)

block-size

b)

width

c)

inline-size

d)

size

119.

Which property enables smooth transitions?

a)

animate

b)

transition

c)

speed

d)

duration

120.

Which property sets spacing between words?

a)

letter-spacing

b)

word-spacing

c)

line-height

d)

text-spacing

121.

Which keyword prevents element wrapping in flexbox?

a)

nowrap

b)

no-wrap

c)

disable-wrap

d)

stop-wrap

122.

Which value makes background repeat only horizontally?

a)

repeat

b)

repeat-y

c)

repeat-x

d)

no-repeat

123.

Which property sets the outline around an element?

a)

border

b)

outline

c)

stroke

d)

frame

124.

Which property sets max width?

a)

max

b)

max-width

c)

limit-width

d)

width-limit

125.

Which unit is scalable with container font size?

a)

rem

b)

px

c)

em

d)

%

126.

Which property changes cursor appearance?

a)

pointer

b)

cursor

c)

mouse

d)

cursor-style

127.

Which value aligns text to both edges?

a)

left

b)

center

c)

right

d)

justify

128.

Which property controls grid gaps?

a)

grid-gap

b)

gap

c)

grid-spacing

d)

spacing

129.

Which property sets a CSS transition’s delay?

a)

transition-wait

b)

delay

c)

transition-delay

d)

animation-delay

130.

Which selector selects the first child?

a)

:first

b)

:first-child

c)

::first

d)

:first-element

131.

Which property makes an element sticky while scrolling?

a)

fixed

b)

absolute

c)

sticky

d)

scroll

132.

Which function rotates an element?

a)

rotate()

b)

transform-rotate()

c)

rotation()

d)

transform()

133.

Which property sets flex item growth?

a)

grow

b)

flex-grow

c)

item-grow

d)

flex-size

134.

Which property sets background size?

a)

bg-size

b)

size

c)

background-size

d)

img-size

135.

Which property defines grid template areas?

a)

grid-template

b)

template-area

c)

grid-area

d)

grid-template-areas

136.

Which pseudoelement targets the first letter?

a)

:first-letter

b)

::first-letter

c)

:letter-first

d)

::letter

137.

Which property adds space between columns?

a)

column-space

b)

column-gap

c)

gap

d)

col-gap

138.

Which property applies a blur effect?

a)

blur

b)

filter: blur()

c)

backdrop

d)

transform-blur

139.

Which position keeps element fixed to viewport?

a)

relative

b)

static

c)

absolute

d)

fixed

140.

Which property sets transition timing function?

a)

timing

b)

transition-function

c)

transition-timing-function

d)

animation-speed

141.

Which value stacks flex items vertically?

a)

row

b)

column

c)

stack

d)

vertical

142.

Which property sets border style?

a)

border

b)

border-outline

c)

border-style

d)

b-style

143.

Which function converts HSL colors?

a)

hsl()

b)

hsl-color()

c)

color-hsl()

d)

hsl-func()

144.

Which shorthand sets font properties?

a)

font

b)

font-all

c)

font-set

d)

type

145.

Which pseudoclass selects checked checkboxes?

a)

:select

b)

:checked

c)

:active

d)

:toggled

146.

Which property sets CSS grid rows?

a)

grid-rows

b)

rows

c)

grid-template-rows

d)

row-template

147.

Which value makes flex items wrap?

a)

wrap

b)

nowrap

c)

wrap-items

d)

auto-wrap

148.

Which property controls overflow scrollbars?

a)

scroll

b)

overflow

c)

scrollbars

d)

overflow-style