wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python 2 Part

Total questions: 119

Worksheet time: 1hrs 25mins

Name
Class
Date
1.

x=15, 18, 19, 24, 95

s=?

(a)  

2.

x=1785, 98718, 12319, 8724, 966195

s=?

(a)  

3.

x=14, 11, 20, 5 , 37

s=?

(a)  

4.

x=878, 1211, 3620, 5875 , 98737

s=?

(a)  

5.

x=87, 11, 362, 58 , 9

s=?

(a)  

6.

N=654

print=?

(a)  

7.

N=987

print=?

(a)  

8.

N=1056

print=?

(a)  

9.

N=1138

print=?

(a)  

10.

N=1379

print=?

(a)  

11.

X=9557

(a)  

12.

X=157

(a)  

13.

X=3674

(a)  

14.

X=8521

(a)  

15.

X=6547

(a)  

16.

x=17

(a)  

17.

x=123

(a)  

18.

x=23

(a)  

19.

x=16

(a)  

20.

x=20

(a)  

21.

x=?

(a)  

22.

s=?

(a)  

23.

n=14

m=20

(a)  

24.

n=1

m=10

(a)  

25.

n=31

m=40

(a)  

26.

n=0

m=11

(a)  

27.

n=10

m=21

(a)  

28.

  • возвращает True, если строка состоит только из алфавитных символов



(a)  

29.

  • : возвращает True, если строка состоит только из символов в нижнем регистре



(a)  

30.

  • : возвращает True, если все символы строки в верхнем регистре



(a)  

31.

  • возвращает True, если все символы строки - цифры



(a)  

32.

  • (str): возвращает True, если строка начинается с подстроки str



(a)  

33.

  • (str): возвращает True, если строка заканчивается на подстроку str



(a)  

34.

  • (): переводит строку в нижний регистр



(a)  

35.

  • (): переводит строку в вехний регистр



(a)  

36.

  • (): начальные символы всех слов в строке переводятся в верхний регистр



(a)  

37.

  • (): переводит в верхний регистр первую букву только самого первого слова строки



(a)  

38.

  • (): удаляет начальные пробелы из строки



(a)  

39.

  • (): удаляет конечные пробелы из строки



(a)  

40.

  • (): удаляет начальные и конечные пробелы из строки



(a)  

41.

  • : возвращает индекс подстроки в строке. Если подстрока не найдена, возвращается число -1



(a)  

42.

  • (old, new[, num]): заменяет в строке одну подстроку на другую



(a)  

43.

  • ([delimeter[, num]]): разбивает строку на подстроки в зависимости от разделителя



(a)  

44.

  • (delimeter): разбивает строку по разделителю на три подстроки и возвращает кортеж из трех элементов - подстрока до разделителя, разделитель и подстрока после разделителя



(a)  

45.

(strs): объединяет строки в одну строку, вставляя между ними определенный разделитель

(a)  

46.

Литерал строки

a)

S = ""str"""

b)

S== "s\ np\ ta\ nbbb"

c)

b"byte"

d)

S1 + S2

e)

S1 * 3

47.

Экранированный список

a)

S = ""str"""

b)

S== "s\ np\ ta\ nbbb"

c)

b"byte"

d)

S1 + S2

e)

S1 * 3

48.

Байтовые строки

a)

S = ""str"""

b)

S== "s\ np\ ta\ nbbb"

c)

b"byte"

d)

S1 + S2

e)

S1 * 3

49.

Конкатенация

a)

S = ""str"""

b)

S== "s\ np\ ta\ nbbb"

c)

b"byte"

d)

S1 + S2

e)

S1 * 3

50.

Умножение строк

a)

S = ""str"""

b)

S== "s\ np\ ta\ nbbb"

c)

b"byte"

d)

S1 + S2

e)

S1 * 3

51.

Поиск по индексу

a)

S[ i ]

b)

S[i:j:step]

c)

len(S)

d)

S.replace

e)

S.split

52.

Вычитание из части

a)

S[ i ]

b)

S[i:j:step]

c)

len(S)

d)

S.replace

e)

S.split

53.

Длина строки

a)

S[ i ]

b)

S[i:j:step]

c)

len(S)

d)

S.replace

e)

S.split

54.

Изменить шаблон

a)

S[ i ]

b)

S[i:j:step]

c)

len(S)

d)

S.replace

e)

S.split

55.

Разделить строку с помощью разделителя

a)

S[ i ]

b)

S[i:j:step]

c)

len(S)

d)

S.replace

e)

S.split

56.

Проверка наличия цифр в строке

a)

S.isdigit()

b)

S.isalpha()

c)

ord

d)

chr

e)

S.lstrip

57.

Проверить, состоит ли строка из букв

a)

S.isdigit()

b)

S.isalpha()

c)

ord

d)

chr

e)

S.lstrip

58.

Его символ ASCII-кода

a)

S.isdigit()

b)

S.isalpha()

c)

ord

d)

chr

e)

S.lstrip

59.

Код ASCII символа

a)

S.isdigit()

b)

S.isalpha()

c)

ord

d)

chr

e)

S.lstrip

60.

Удаление пробелов в начале строки

a)

S.rstrip

b)

S.strip

c)

S.format

d)

str.isupper

e)

S.lstrip

61.

Удаление пробелов в конце строки

a)

S.rstrip

b)

S.strip

c)

S.format

d)

str.isupper

e)

S.lstrip

62.

Удаление пробелов в конце и в начале строки

a)

S.rstrip

b)

S.strip

c)

S.format

d)

str.isupper

e)

S.lstrip

63.

Форматирование строки

a)

S.rstrip

b)

S.strip

c)

S.format

d)

str.isupper

e)

S.lstrip

64.

Проверяет, состоит ли строка только из символов в верхнем регистре

a)

S.rstrip

b)

S.strip

c)

S.format

d)

str.isupper

e)

S.lstrip

65.

s="информатика"

print(s[3:5])

a)

ор

b)
ка
c)
мата
d)
ин
66.

s="информатика"

print(s[2:-2])

a)

форматик

b)
информация
c)

формати

d)
форматирование
67.

s="информатика"

print(s[-4:-2])

a)

тик

b)
орма
c)
инф
d)

ти

68.

s="информатика"

print(s[:6])

a)
информ
b)
информатик
c)
информат
d)
информатика
69.

s="информатика"

print(s[1:])

a)
нформатика
b)
нформатик
c)
нформатикa
d)
информатика
70.

s="информатика"

print(s[:])

a)
информатика1
b)
информатика2
c)
информатика3
d)
информатика
71.

string = "Python Programming"

print(string.lower())

print(string.upper())

a)

python programming

PYTHON PROGRAMMING

b)
Python programming 101
c)

PYTHON PROGRAMMING

python programming

d)
python programming language
72.

string = "Data Science"

print(string.lower())

print(string.upper())

a)
data science and AI
b)

data science

DATA SCIENCE

c)

DATA SCIENCE

data science

d)
data science 101
73.

string = "Python is fun"

print("Python" in string)

print("python" in string)

a)
True, True
b)
True, False
c)
False, True
d)

False, False

74.

string = "Machine Learning"

print("Learning" in string)

print("machine" in string)

a)
True, True
b)
True, False
c)
False, True
d)

False, False

75.

print("Python".isalpha())

print("2023".isdigit())

a)
False, False
b)
True, False
c)
True, True
d)
False, True
76.

print("data science is fun".title())

print("data science is fun".capitalize())

a)

Data Science Is Fun

Data science is fun

b)

Data science is fun

Data Science Is Fun

c)

data science Is Fun

Data Science Is Fun,

d)

Data Science is fun

Data Science Is Fun,

77.

print("python programming".title())

print("python programming".capitalize())

a)

Python programming Python Programming

b)

Python Programming Python programming

c)

PYTHON PROGRAMMING

python programming

d)

Python programming python Programming

78.

string = "Python is awesome"

print(string.find("is"))

print(string.find("IS"))

a)
6, 1
b)
7, 0
c)
-1, 7
d)
7, -1
79.

string = "Info Learning is cool"

print(string.find("Learning"))

print(string.find("Info"))

a)

5, -1

b)
4, 2
c)
6, 1
d)
5, 0
80.

string = "Hello, World!"

print(string.replace("World", "Python"))  #

print(string.replace("o", "O", 1))       

a)

Hello, Python!

HellO, WOrld!

b)
Hello, Python!
c)

HellO, Python!

HellO, PythOn!

d)
Hello, Python! HellO, World!
81.

string = "apple,banana,orange,grape"

print(string.split(","))

print(string.split(",", 2))

a)

['apple', 'banana', 'grape']

['apple', 'banana', 'grape']

b)
['apple,banana', 'orange', 'grape']
c)
['apple', 'banana', 'orange', 'grape', 'kiwi']
d)

['apple', 'banana', 'orange', 'grape']['apple', 'banana', 'orange,grape']

82.

words = ["apple", "banana", "orange"]

print("-".join(words))

print(", ".join(words))

a)
apple, orange, banana
b)

apple-banana-orange

apple, banana, orange

c)

banana-orange-apple orange, apple

d)

apple-banana-orange banana, orange

83.

words = ["one", "two", "three", "four"]

print(" ".join(words))

print("/".join(words))

a)
one; two; three; four
b)

one/two three/four

one two three four

c)
one two three four one/two/three/four
d)

one/two/three/four

one, two, three, four

84.

words = ["cat", "dog", "bird"]

print(";".join(words))

print(" -> ".join(words))

a)
cat -> dog; bird
b)
cat,dog,bird
c)

cat -> bird -> dog

cat;dog;bird

d)
cat;dog;bird cat -> dog -> bird
85.

country= {'code':'UK', 'name':'United Kingdom', 'population':'50'} ​
print(country['code'])​

a)

United Kingdom

b)
UK
c)

50

d)

code

86.

country= {'code':'UK', 'name':'United Kingdom', 'population':'50'} ​
print(country.get('code')​)

a)

United Kingdom

b)
UK
c)

50

d)

code

87.

country= {'code':'UK', 'name':'United Kingdom', 'population':'50'} ​
country.pop('code')

print(country)

a)
{'code': 'UK', 'population': '50'}
b)
{'name': 'UK', 'population': '50'}
c)
{'name': 'United Kingdom', 'population': '50'}
d)
{'code': 'UK', 'name': 'United Kingdom'}
88.

country= {'code':'UK', 'name':'United Kingdom', 'population':'50'} ​
country.popitem()​

print(country)

a)
{'name': 'United Kingdom', 'population': '50'}
b)
{'code': 'US', 'name': 'United States', 'population': '300'}
c)
{'code': 'UK', 'name': 'United Kingdom'}
d)
{'code': 'UK', 'population': '50'}
89.

data = {'id': 101, 'name': 'Alice', 'age': 25}

print(data['id'])

a)
25
b)
Alice
c)
101
d)
102
90.

data = {'id': 101, 'name': 'Alice', 'age': 25}

print(data.get('name'))

a)

25

b)

101

c)

id

d)
Alice
91.

data = {'id': 101, 'name': 'Alice', 'age': 25}

data.pop('age')

print(data)

a)
{"id": 101, "name": "Alice"}
b)
{"id": 101, "age": 25}
c)
{"id": 102, "name": "Bob"}
d)
{"name": "Alice", "age": 25}
92.

data = {'id': 101, 'name': 'Alice', 'age': 25}

data.popitem()

print(data)

a)
{"id": 101, "name": "Alice"}
b)
{"id": 102, "name": "Bob"}
c)
{"name": "Alice", "age": 25}
d)
{"id": 101, "age": 25}
93.

it = {1, 2, 3, 1, 3, 4, 2, 5}

print(it, type(it))

a)

{1, 2, 3, 1, 3, 4, 2, 5}<class 'set'>

b)

{1, 2, 3, 4, 5} <class 'set'>

c)

{1, 2, 3, 4, 5, 6}<class 'set'>

d)

{1, 2, 3, 4, 5}

94.

it = {'a', 'v', 'i', 'e', 'a', 'v'}

print(it)

a)
{'a', 'v', 'i', 'e'}
b)
{'a', 'v', 'e', 'a', 'v'}
c)
{'a', 'v', 'i'}
d)
{'a', 'v', 'i', 'e', 'a'}
95.

it = set('Infomat is cool')

print(it)

a)
{'I', 'n', 'f', 'o', 'm', 'a', 't', ' ', 'i', 's', 'c', 'l'}
b)
{'I', 'n', 'f', 'o', 'm', 'a', 't', ' ', 'i', 's', 'c', 'o', 'l'}
c)
{'I', 'n', 'f', 'o', 'm', 'a', 't', 'i', 's', 'c', 'l'}
d)
{'I', 'n', 'f', 'o', 'm', 'a', 't', ' ', 'i', 's', 'c', 'l', 'e'}
96.

numbers = {10, 20, 30, 20, 40, 50}

print(numbers)

a)
{10, 20, 30, 20, 40, 50}
b)
{20, 30, 40, 50}
c)
{10, 20, 30, 40, 50, 60}
d)
{10, 20, 30, 40, 50}
97.

chars = set('banana')

print(chars)

a)
{'b', 'a', 'n', 'c'}
b)
{'b', 'a', 'n'}
c)
{'b', 'n'}
d)
{'b', 'a', 'n', 'a'}
98.

set1 = {1, 2, 3}

set2 = {3, 4, 5}

print(set1 | set2)

a)
{2, 3, 5}
b)
{1, 2, 3, 4, 5}
c)
{1, 2, 3}
d)
{3, 4}
99.

set1 = {1, 2, 3}

set2 = {3, 4, 5}

Run=>{1, 2, 3, 4, 5}



(a)  

100.

set1 = {1, 2, 3}

set3 = {5, 6, 7}

print(set1 & set3)

a)
set()
b)
{1, 2, 3, 4}
c)
{5, 6}
d)
{1, 2, 3, 5, 6, 7}
101.

set1 = {1, 2, 3 , 4}

set3 = {4, 5, 6, 7}

Run=>{4}



(a)  

102.

set5 = {8, 9, 10}

set5.add(11)

print(set5)

a)
{8, 9, 10}
b)
{10, 11}
c)
{8, 9, 10, 12}
d)
{8, 9, 10, 11}
103.

set6 = {12, 13, 14}

set6.remove(13)

print(set6)

a)
{13, 14}
b)
{12, 13, 14}
c)
{12, 13}
d)
{12, 14}
104.

it={1, 2, 3, 5, 6, 1, 4, 5}

it.update([5, 6, 7, 8, 10])

print(it)

a)
{1, 2, 3, 5, 6, 7, 8, 10}
b)
{1, 2, 3, 4, 5, 6, 10}
c)
{1, 2, 3, 4, 5, 6, 7, 8}
d)
{1, 2, 3, 4, 5, 6, 7, 8, 10}
105.

it={1, 2, 3, 5, 6, 1, 4, 5}

it.update('Mr Rom' )

print(it)

a)
{1, 2, 3, 4, 5, 6, 'Mr Rom'}
b)
{1, 2, 3, 4, 5, 6, 'M', 'r', ' ', 'R', 'o', 'm'}
c)
{1, 2, 3, 5, 6, 'M', 'r', 'o', 'm'}
d)
{1, 2, 3, 5, 6, 4, 5}
106.

it = {1, 2, 3}

it.update({4, 5}, [6, 7])

print(it)

a)
{1, 2, 3, 4, 5}
b)
{1, 2, 3, 4, 5, 6, 7}
c)
{1, 2, 3, 6, 7}
d)
{4, 5, 6, 7}
107.

it={1, 2, 3, 5, 6, 1, 4, 5}

print(len(it))

a)
6
b)
8
c)
7
d)
5
108.

it={1, 2, 3, 5, 6, 1, 4, 5}

print(4 in it)

a)
True
b)
0
c)
None
d)
False
109.

it={1, 2, 3, 5, 6, 1, 4, 5}

print(7 in it)

a)
True
b)
0
c)
None
d)
False
110.

it = set()

it.update('OpenAI')

print(it)

a)
{'O', 'p', 'e', 'n', 'A', 'I', 'x'}
b)
{'O', 'p', 'e', 'n', 'I', 'A', 'n'}
c)
{'O', 'p', 'e', 'n', 'A'}
d)
{'O', 'p', 'e', 'n', 'A', 'I'}
111.

it = {'apple', 'banana'}

it.update({'cherry', 'date'})

print(it)

a)
{'apple', 'cherry', 'date'}
b)
{'apple', 'banana', 'cherry', 'date'}
c)
{'cherry', 'date'}
d)
{'apple', 'banana'}
112.

a={1,4,3,2}

b={3,4,5,6,7}

print(a^b)

a)
{2, 4, 5, 6}
b)
{3, 4, 6, 7}
c)
{1, 2, 5, 6, 7}
d)
{1, 2, 3, 4}
113.

a={1,4,3,2}

b={3,4,5,6,7}

print(a-b)

a)
{3, 4, 5, 6, 7}
b)
{1, 2, 3}
c)
{4, 5, 6, 7}
d)
{1, 2}
114.

a={1,4,3,2}

b={3,4,5,6,7}

RUN=>{1, 2}



(a)  

115.

a={1,4,3,2}

b={3,4,5,6,7}

RUN=>{5, 6, 7}



(a)  

116.

setA = {1, 2, 3, 4}

setA.add(5)

print(setA)

a)

{1, 2, 3, 4}

b)

{1, 2, 3, 4, 5}

c)

{1, 2, 3, 4, 6}

d)

{1, 2, 3, 5}

117.

fruits = {'apple', 'banana', 'cherry'}

fruits.remove('banana')

print(fruits)

a)

{'apple', 'banana'}

b)

{'apple', 'banana', 'cherry'}

c)

{'apple', 'cherry'}

d)

{'banana', 'cherry'}

118.

data = {'name': 'Bob', 'age': 30}

data['age'] = 31

print(data)

a)

{'age': 31, 'name': 'Bob'}

b)

{'age': 30, 'name': 'Bob'}

c)

{'name': 'Bob', 'age': 31}

d)

{'name': 'Bob', 'age': 30}

119.

b={3,4,5,6,7}​

c={10,12,14}​

Run=>{3, 4, 5, 6, 7, 10, 12, 14}​

(a)