wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz for beginners

Total questions: 65

Worksheet time: 33mins

Name
Class
Date
1.

Which of the following is a valid Python identifier?

a)

2value

b)

value_2

c)

value-2

d)

value 2

2.

Which keyword is used to define a function in Python?

a)

func

b)

define

c)

def

d)

function

3.

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

a)

<class 'str'>

b)

<class 'int'>

c)

<class 'float'>

d)

<class 'bool'>

4.

Which operator is used for exponentiation in Python?

a)

^

b)

**

c)

*

d)

exp()

5.

What is the result of 3 + 4 * 2 in Python?

a)

14

b)

11

c)

10

d)

7

6.

Which of the following is a mutable data type?

a)

tuple

b)

str

c)

list

d)

int

7.

What does indentation signify in Python?

a)

Comments

b)

Loop

c)

Block of code

d)

Variable

8.

Which symbol is used to write a comment in Python?

a)

//

b)

#

c)

/* */

d)

--

9.

What function is used to read input from the user?

a)

input()

b)

read()

c)

scan()

d)

get()

10.

What is the output of print("Hello", end=" ")?

a)

Hello end

b)

Hello\n

c)

Helloend

d)

Hello

11.

Which statement is used to skip the current iteration in a loop?

a)

skip

b)

continue

c)

break

d)

pass

12.

What is the output of bool("False")?

a)

False

b)

True

c)

Error

d)

None

13.

Which of the following is a correct way to convert a string to an integer?

a)

int("123")

b)

str(123)

c)

float("123")

d)

bool("123")

14.

What does the is operator check?

a)

Value equality

b)

Type equality

c)

Identity

d)

Membership

15.

Python is considered a:

a)

Weakly typed language

b)

Dynamically typed language

c)

Statically typed language

d)

Low-level language

16.

How do you create a single element tuple

a)

tuple(10)

b)

(10)

c)

(10,)

d)

[10]

17.

What is the default return value of a Python function that doesn't explicitly return anything?

a)

0

b)

None

c)

False

d)

undefined

18.

Which of the following is a correct function definition?

a)

def myfunc:

b)

function myfunc()

c)

def myfunc():

d)

define myfunc()

19.

What is the scope of a variable declared inside a function?

a)

Global

b)

Local

c)

Static

d)

Dynamic

20.

Which statement is used to exit a function and return a value?

a)

break

b)

exit

c)

return

d)

stop

21.

What is the output of "Python"[0]?

a)

P

b)

y

c)

n

d)

o

22.

Which method is used to convert a string to lowercase?

a)

lowercase()

b)

toLower()

c)

lower()

d)

down()

23.

What does the len() function return when applied to a string?

a)

Number of words

b)

Number of characters

c)

Number of lines

d)

Number of vowels

24.

Which operator is used to concatenate strings in Python?

a)

+

b)

&

c)

*

d)

%

25.

What is the output of "abc" * 3?

a)

abcabcabc

b)

abc3

c)

abc abc abc

d)

abc*3

26.

Which method adds an item to the end of a list?

a)

insert()

b)

append()

c)

add()

d)

extend()

27.

Which of the following creates a list?

a)

{1, 2, 3}

b)

(1, 2, 3)

c)

[1, 2, 3]

d)

<1, 2, 3>

28.

What is the index of the first element in a Python list?

a)

1

b)

0

c)

-1

d)

None

29.

Which method removes all items from a list?

a)

delete()

b)

clear()

c)

remove()

d)

pop()

30.

Which method is used to get all keys from a dictionary?

a)

keys()

b)

values()

c)

items()

d)

get()

31.

What is the output of len({"a":1, "b":2})?

a)

1

b)

2

c)

3

d)

0

32.

Which method is used to remove a key from a dictionary?

a)

delete()

b)

remove()

c)

pop()

d)

discard()

33.

What is the correct syntax to access the value of key "name" in a dictionary d?

a)

d.name

b)

d["name"]

c)

d(name)

d)

d->name

34.

Which method returns all key-value pairs in a dictionary?

a)

keys()

b)

values()

c)

items()

d)

pairs()

35.

Which of the following defines a tuple?

a)

[1, 2, 3]

b)

{1, 2, 3}

c)

(1, 2, 3)

d)

<1, 2, 3>

36.

Tuples are:

a)

Mutable

b)

Immutable

c)

Dynamic

d)

Expandable

37.

Which method is used to count occurrences of an element in a tuple?

a)

count()

b)

index()

c)

find()

d)

search()

38.

Which of the following creates a set?

a)

{1, 2, 3}

b)

[1, 2, 3]

c)

(1, 2, 3)

d)

set(1,2,3)

39.

Sets are:

a)

Ordered

b)

Mutable

c)

Allow duplicates

d)

Immutable

40.

Which method adds an element to a set?

a)

append()

b)

add()

c)

insert()

d)

extend()

41.

What is the difference between set and frozenset?

a)

No difference

b)

frozenset is mutable

c)

set is immutable

d)

frozenset is immutable

42.

Which method removes all elements from a set?

a)

clear()

b)

remove()

c)

discard()

d)

pop()

43.

Which of the following is used to define a block of code in Python?

a)

Braces {}

b)

Parentheses ()

c)

Indentation

d)

Semicolon ;

44.

What is the output of len(set([1, 2, 2, 3]))?

a)

2

b)

3

c)

4

d)

1

45.

Which function is used to get the index of an element in a tuple?

a)

find()

b)

search()

c)

index()

d)

position()

46.

What is the output of print("Hello" + str(5))?

a)

Hello5

b)

Hello 5

c)

Hello

d)

Error

47.

You are given a list numbers = [1, 2, 2, 3, 4]. You convert it into a set using unique = set(numbers) and then print len(unique). What will be the output?

a)

5

b)

4

c)

3

d)

2

48.

Consider the tuple data = (10, 20, 30, 40). What will be the result of print(data[-1])?

a)

10

b)

20

c)

30

d)

40

49.

text = "Python Programming"

reversed_text = text[::-1]

What will be printed when you run print(reversed_text)?

a)

gnimmargorP nohtyP

b)

PythonProgramming

c)

ProgrammingPython

d)

Error

50.

You have two lists: a = [1, 2] and b = [3, 4]. You perform result = a + b and print it. What will be the output?

a)

[1, 2, 3, 4]

b)

[4, 3, 2, 1]

c)

[1, 2][3, 4]

d)

Error

51.

A dictionary info = {"name": "Alice", "age": 25} is defined. You access the value of the key "age" using print(info["age"]). What will be printed?

a)

Alice

b)

name

c)

25

d)

Error

52.

You define a string s = "abc" and multiply it by 3 using print(s * 3). What will be the output?

a)

abcabcabc

b)

abc3

c)

abc abc abc

d)

Error

53.

A tuple t = (1, [2, 3], "hello") is created. You want to find out how many elements are in the tuple using len(t). What will be the result?

a)

2

b)

3

c)

1

d)

5

54.

You have a string greeting = "hello" and apply the method greeting.upper() and print the result. What will be displayed?

a)

HELLO

b)

hello

c)

Hello

d)

error

55.

A list items = [10, 20, 30] is defined. You use items.pop() to remove and return the last element. What will be printed?

a)

10

b)

20

c)

30

d)

Error

56.

What will be the output of print({1, 2, 3} & {2, 3, 4})?

a)

{1,4}

b)

{2,3}

c)

{1,2,3,4}

d)

Error

57.

What will be the output of print([i for i in range(5) if i % 2 == 0])

a)

[1, 3, 5]

b)

[0, 2, 4]

c)

[2, 4]

d)

[0, 2]

58.

What will be the output of print({x: x**2 for x in range(3)})?

a)

{0: 0, 1: 1, 2: 4}

b)

{1: 1, 2: 4}

c)

{0: 1, 1: 2, 2: 3}

d)

Error

59.

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

a)

True

b)

False

c)

Error

d)

None

60.

fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
print(fruits[:3])     

a)

['banana', 'cherry', 'date']

b)

['apple', 'banana', 'cherry'] 

c)

['cherry', 'date', 'elderberry']

d)

['apple', 'cherry', 'elderberry']

61.

What will be the output of the following code?

def f(x=[]):

    x.append(1)

    return x

print(f())

print(f())

a)

[1] [1]

b)

[1] [1, 1]

c)

[1, 1] [1, 1, 1]

d)

Error

62.

Which of the following operations is not allowed on a tuple?

a)

t[0]

b)

t.index(5)

c)

len(t)

d)

t.append(3)

63.

What is the output of this code?

s = set("hello")

s.add("h")

print(len(s))

a)

5

b)

6

c)

4

d)

Error

64.

Consider the code:

lst = [1, 2, 3]

print(lst * 2)

lst *= 2

print(lst)

a)

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

b)

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

c)

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

d)

Error

65.

What does this function return?

def mystery(a, b):

    return a if a > b else b if b > a else a + b

print(mystery(3, 3))

a)

3

b)

6

c)

9

d)

Error