wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python with Functions

Total questions: 50

Worksheet time: 26mins

Name
Class
Date
1.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
2.
What will the output be from the following code?
print(3+4)
a)

3+4

b)

7

c)

SyntaxError

d)

print(3+4)

3.
print("12"*3)
What would this print?
a)
36
b)
121212
c)
24
d)
12*3
4.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
5.

Which of the following is the correct extension of the Python file?

a)

a) .python

b)

b) .pl

c)

c) .py

d)

d) .p

6.

What will be the value of the following Python expression?

4 + 3 % 5

a)

a) 7

b)

b) 2

c)

c) 4

d)

d) 1

7.

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

a)

a) Indentation

b)

b) Key

c)

c) Brackets

d)

d) All of the mentioned

8.

Which of the following character is used to give single-line comments in Python?

a)

a) //

b)

b) #

c)

c) !

d)

d) /*

9.
The number or word we give to a variable
a)
Value
b)
Bug
c)
Information
d)
Text
10.

What is the order of precedence in python?

a)

a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

11.

Which of the following functions is a built-in function in python?

a)

a) factorial()

b)

b) print()

c)

c) seed()

d)

d) sqrt()

12.

Which of the following is not a core data type in Python programming?

a)

a) Tuples

b)

b) Lists

c)

c) Class

d)

d) Dictionary

13.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

14.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
15.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

16.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

17.

What will be the output of the “hello” +1+2+3?

a)

a) hello123

b)

b) hello

c)

c) Error

d)

d) hello6

18.

chose which is a floating point

a)

14

b)

15.5

19.

chose a string

a)

"tim"

b)

"tim

c)

'tim'

d)

"tim

e)

tim

20.

where is python used

a)

web aplications

b)

data science

c)

mobile apps

d)

GUI applications

21.

Which is the correct operator for power  xyx^y  

a)

x^y

b)

x**y

c)

x^^y

d)

None of these

22.
What syntax can you use to insert a line break between strings so that they appear over multiple lines?
a)
/
b)
\n
c)
\l
d)
n
23.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

24.

Which of the following create an empty dictionary (D)?

a)

D = dict()

b)

D = ()

c)

D = []

d)

D = {}

25.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
26.
is this code correct?
quiz = ("Do you help out at home? ":"yes"      }
a)
No
b)
Yes
c)
Both
27.

Which method will remove an element the Dictionary data type?

a)

.pop()

b)

.discard()

c)

.remove()

28.

Lists use _____ to access values

a)

values

b)

indexes

c)

key values

d)

keys

29.

Consider this list, what will be the highest index the list can have:

li=[1,2,3,4,5]

a)

2

b)

3

c)

4

d)

5

30.

Consider this list, what will be the output of the following:


li=[1,2,3,4,3,2,1]

print(li[-3])

a)

4

b)

3

c)

2

d)

1

31.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

32.

Each item in a list has an index. What is the first index in a Python list?

a)

0

b)

1

c)

a

d)

A

33.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
34.

What will be the output of this program?


def hello():

print(“I am a beginner”)

hello()

hello()

a)

I am a beginner

b)

I am a beginner I am a beginner

c)

Hello

d)

Hello

Hello

e)

I am a beginner

I am a beginner

35.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

36.

The default return value of any function in Python is _______________.

a)

null

b)

0

c)

None

d)

Garbage value

37.

__________ is the built-in function to know the type of a variable or function.

a)

id()

b)

type()

c)

data_type()

d)

none of the above

38.

times is ________________ type of argument.

a)

default arguments

b)

keyword arguments

c)

positional arguments

d)

arbitrary positional arguments

e)

arbitrary keyword arguments

39.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

40.

One of the following functions is not used with Python String

a)

Split

b)

Remove

c)

print

d)

Replace

41.

Choose the correct syntax of the split function:

a)

x.split[]

b)

split(x)

c)

x.split(",", 3)

d)

X.SPLIT(",", 3)

42.

Choose the correct syntax of the replace function:

a)

x.Replace(x)

b)

x.replace(y)

c)

x.replace(3,x)

d)

x.replace("j","3")

43.

Choose the correct code to print line of 10 stars using repetition operation:

a)

print("**********")

b)

print("*"*10)

c)

print("*"^10)

d)

print("*"+10)

44.

The correct syntax of the len function for string x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

45.

The correct syntax for converting the string x to uppercase is :

a)

X.upper()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

46.

The correct syntax for converting the string myname to lowercase is :

a)

myNAME.lower[ ]

b)

myname.lower( )

c)

myname.upper( )

d)

myname_lower(12 )

47.

To remove the spaces present at start and end of the string, you can use

a)

split()

b)

len()

c)

strip()

d)

remove()

48.

Let x= "Python", the output of print(x.upper()) is

a)

python

b)

PYTHON

c)

_PYTHON

d)

"PYTHON"

49.

str1='101'

x=int(str1)

z=x+400

print(z)

a)

101400

b)

x400

c)

501

d)

none of above

50.

What is the purpose of a function?

a)

They are reusable pieces of programs.

b)

They are required by the Python

c)

They allow us to compile our program

d)

They make the program larger