wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Final 23

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is Python?

a)

A snake

b)

A programming language

c)

A software

d)

A type of food

2.

What is used to define a block of code in Python?

a)

Curly braces

b)

Parentheses

c)

Indentation

d)

Quotation

3.

How can you create a comment in Python?

a)

Using the // symbol

b)

Using the /*...*/ symbol

c)

Using the # symbol

d)

Using the -- symbol

4.

Which Python function will you use to read input data from the user?

a)

input()

b)

raw_input()

c)

read_input()

d)

collect_input()

5.

How do you create a variable "a" that is equal to 2 in Python?

a)

int a = 2

b)

var a = 2

c)

a = 2

d)

2 = a

6.

Which of the following is not a valid Python data type?

a)

 List

b)

Tuple

c)

Dictionary

d)

Table

7.

How do you create a list in Python?

a)

a = (1, 2, 3)

b)

a = [1, 2, 3]

c)

a = {1, 2, 3}

d)

a = '1, 2, 3'

8.

What will be the output of the following Python code snippet: print(10 > 9)

a)

10

b)

9

c)

True

d)

False

9.

How can we generate random numbers in Python?

a)

import random

b)

import randomnumber

c)

 import random_number

d)

 import randint

10.

How do you write a function in Python?

a)

def function_name():

b)

function_name():

c)

 function function_name():

d)

 func function_name():

11.

What is the first index of a list in Python?

a)

0

b)

1

c)

-1

d)

Depends on the list

12.

How do you check if a Python string, s, ends with a specific character, c?

a)

s.endswith(c)

b)

s.ends(c)

c)
d)

s.last(c)

13.

How do you convert a string s to a list in Python?

a)

list(s)

b)

to_list(s)

c)

convert_list(s)

d)

s.list()

14.

How do you get the length of a list, l, in Python?

a)

 length(l)

b)

len(l)

c)

l.length()

d)

l.len()

15.

What is the output of the following Python code: print("Hello, World!".lower())

a)

hello, world!

b)

Hello, World!

c)

HELLO, WORLD!

d)

None of the above

16.

Which keyword is used for function declaration in Python?

a)

func

b)

function

c)

define

d)

def

17.

What will be the output of the following code: print(len("Python"))

a)

5

b)

6

c)

7

d)

8

18.

Which Python keyword indicates the start of a loop?

a)

start

b)

 loop

c)

begin

d)

for

19.

How do you create a dictionary in Python?

a)

 a = (1="one", 2="two", 3="three")

b)

 a = [1="one", 2="two", 3="three"]

c)

a = {1: "one", 2: "two", 3: "three"}

d)

a = '1="one", 2="two", 3="three"'

20.

How do you create a tuple in Python?

a)

a = (1, 2, 3)

b)

a = [1, 2, 3]

c)

a = {1, 2, 3}

d)

a = '1, 2, 3'

21.

What does the following Python statement do: import numpy as np

a)

Imports all functions from the numpy library

b)

Imports the numpy library and it can be referenced as np

c)

 Imports a specific function named numpy from the np library

d)

Imports a specific function named np from the numpy library

22.

What is the output of this statement: print("2" + "2")

a)

4

b)

22

c)

"4"

d)

"22"

23.

What keyword is used to create a class in Python?

a)

def

b)

class

c)

Class

d)

Define

24.

How can you get the type of variable or object x in Python?

a)

get_type(x)

b)

 x.type()

c)

 type(x)

d)

x.get_type()

25.

How do you convert a string s to an integer in Python?

a)

int(s)

b)

to_int(s)

c)
d)

s.to_int()