Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Test 5A

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Select the correct output of the following String operations.

str1 = "my isname isisis jameis isis bond";

sub = "is";

print(str1.count(sub, 4))

a)

5

b)

6

c)

7

d)

3

2.

Select the correct output of the following String operations

str1 = 'Welcome'

print (str1[:6] + ' PYnative')

a)

 Welcome PYnative

b)

WelcomPYnative

c)

Welcom PYnative

d)

WelcomePYnative

3.

Guess the correct output of the following String operations

str1 = 'Welcome'

print(str1*2)

a)

 WelcomeWelcome

b)

TypeError unsupported operand type(s)

c)

Welcome Welcome

d)

ValueError unsupported operand type(s)

4.

Choose the correct function to get the ASCII code of a character

a)

char('char')

b)

ord('char')

c)

 ascii('char')

d)

asc('char')

5.

Choose the correct function to get the character from ASCII number

a)

 ascii(number)

b)

 char(number)

c)

 chr(number)

d)

asc(number)

6.

What will be the output of above Python code?

str1="6/4"

print("str1")

a)

1

b)

6/4

c)

1.5

d)

str1

7.

Which of the following will result in an error?

str1="python"

a)

print(str1[2])

b)

str1[1]="x"

c)

print(str1[0:9])

d)

Both (b) and (c)

8.

What will be the output of below Python code?

str1="Aplication"

str2=str1.replace('a','A')

print(str2)

a)

application

b)

Application

c)

ApplicAtion

d)

applicAtion

9.

What will be the output of below Python code?

str1="poWer"

str1.upper()

print(str1)

a)

POWER

b)

Power

c)

power

d)

poWer

10.

Which of the following will give "Simon" as output?

If str1="John,Simon,Aryan"

a)

print(str1[-7:-12])

b)

print(str1[-11:-7])

c)

print(str1[-11:-6])

d)

print(str1[-7:-11])