Font size
WorksheetsPython Object Types and Data Types Worksheet
Total questions: 101
Worksheet time: 51mins
1. В Python типы объектов определяются в процессе исполнения программы (runtime) (т.е. с определенным типом связывается не переменная, а ее значение):
Data analysis
Dynamic typing
Flow control
Vectorization
Clustering
Representation of name (Names given to object references) in code Python:
Literal
Numbers
Identifier
String
Operator
The name associated with the value of the data type is used to track changes in the values during the calculation in Python:
Literal
Variable
Numbers
String
Identifier
The str data type for processing character sequences:
Literal
Numbers
String
Identifier
Operator
The int data type:
Literal
String
Float
Integer
Operator
Float data type, decimal digits:
Literal
Integer
Float
String
Operator
Bool data type, True and False values:
Integer
String
Float
Boolean
Operator
Python. To describe the change in the order of operators in the program, the term is used.
Change case
Concatenation
Control flow
Delete Gaps
Logical OR
Instructions when operators may or may not be executed depending on certain conditions:
Control flow
Concatenation
Conditional expressions
Delete Gaps
Logical OR
Python. Logical Operator - Inverse:
Control flow
Logical NOT
Concatenation
Delete Gaps
Logical OR
Python. Instructions, if the condition is true, then an expression block (called an “if block”) is executed, otherwise another expression block (called an “else block”) is executed:
if – elif – else
Контроль потока (control flow)
Циклы (loop)
for
while
12. Python. Comment Operator:
Контроль потока (control flow)
Циклы (loop)
if – elif - else
for
#
Operator to print any value passed to it:
Control flow
print ()
continue
for -in
while
14. Python. Input operator:
if – elif - else
for -in
while
input ()
print ()
Instructions where certain operators can be executed multiple times, depending on certain conditions:
Control flow
Условные выражения if – elif - else
Циклы (loop)
Пакет
Словарь
Function that is used to input text:
input ()
key()
values()
del
pop()
Python. Built-in function that converts object x to an integer:
list(x)
int (x)
float(x)
tuple(x)
str (x)
Python. Built-in function that converts object x to a string:
int(x)
list(x)
str(x)
float(x)
tuple(x)
Built-in function that converts object x to float:
str(x)
int(x)
float(x)
list(x)
tuple(x)
Instruction for displaying the first values of the list:
print(lst[1])
print(lst[0])
lst = [[1, 2, 3], [4, 5, 6]]
max(lst)
list = ['January', 'February', 'March'], 3
The value of the variable c after program run:
c = 440
c = -240
a = 40
a = 2.5
b = 10
Determine the values of the variables x and y, with conditions that x = 15, y = 2:
x = 15, y = 2
x = 2, y = 15
x = 10, y = 5
x = 5, y = 10
m= 40
The result of the program with a value of x=6: if x>5: print('x>5') elif x<5: print('x<5') else: print('x=5') if x>7 and x<9: print('x=8') if x == 1 or x == 3: print('x=1 or 3')
x= 2
x>5
x= 5
x< 5
x= 8
Operators to output the float value of a variable x=5.123:
print ('%.3f' % x)
print('x=5')
print(5)
print(a*b)
print ('% 8.5f' % x)
Operators to output the float value of a variable x = -2.12 (наиболее оптимальный):
print('x=5')
print ('% 5.2f' % x)
print(5)
рrint (‘% .3f ‘% x)
рrint (‘% 7.5f ‘% x)
Loop executing loop body until boolean expression is True:
if
else
elif
while
for …in
A loop executing a loop body a specific number of times (конкретное число раз):
if
else
elif
for …in
while
Python. Loop statement that interrupts a loop:
Control flow
break
continue
if – elif – else
for -in
An operator that gives instructions that it is necessary to skip all the remaining commands in the current block of the loop and continue from the next iteration of the loop:
Control flow
continue
if – elif – else
for -in
while
The result of the program for i in 1, 2, 3, 'one', 'two': print(i, end=' ')
1 2 3
1 2 3 one two
1 2 3 one
1,2,3, one, two
1-2-3-one-two
The result of the program for i in range (4): print (i, end='/ ')
0 1 2 3
1 2 3 one
0\1\2\3
1 2 3 one two
1,2,3, one, two
The result of the program sum = 0 n = 3 for i in range (1, n + 1): sum += i print (sum)
15
6
3
10
25
The result of the program n = 0 for i in range (1, 6): n = n+i print(n)
5
15
6
10
25
The result of the program: value i and j: for i in range (1, 2): print ('i', i) for j in range (1, 3): print ('j', j)
i =1, j = 2
i = 2, j = 3
i = 3, j = 4
i = 3, j = 3
The result of the program: value s1 and s2: s=0 s1=0 i=1 while i<4: s=s+1 i+=1 j=1 while j<2: s1=s1+1 j+=1 print(s) print(s1)
s = 2, s1 = 1
s = 1, s1 = 2
s = 3, s1 = 3
s = 0, s1 = 2
s = 1, s1 = 3
The values of the variable i when executing the loop: for i in range(2, 10, 2): print(i, end=" ")
0, 1, 2, 3
5, 4, 3, 2, 1
2, 4, 6, 8
1, 2, 3, 4, 5
1 2 4 6 8
The values of the variable i when executing the loop: a = 6 b = 2 for i in range(a, b+1, -1): print(i, end=", ")
2, 4, 6, 8
6, 5, 4
0, 1, 2, 3
5, 4, 3, 2, 1
1 2 4 6 8
How many times the loop will run (How many numbers will the program print): i = 4 while i >= 0: print(i) i = i - 1
3
4
5
10
2
Insert missing statement in program that prints even numbers (печатает четные числа): x = 0 ____ x <= 20: print(x) x += 2
if
elif
while
for
list
Set the step value in the function range() to the program so that numbers are printed: 2 5 8 11: a = 2 b = 11 for i in range(a, b+1, __): print(i, end=' ');
2
3
1
4
-3
A set of elements in a specific order is indicated by square brackets ([ ]):
Literal
List
Numbers
String
Operator
Python. List items are accessed based on:
Literal
Index
Numbers
String
Operator
Method for adding new element x to the end of the lst list:
lst.extend(t)
lst.append(x)
lst.index(x)
lst.pop(i)
lst.insert(i, x)
Method for adding new element x to position i of the lst list:
lst.append(x)
lst.extend(t)
lst.insert(i, x)
lst.index(x)
lst.pop(i)
Method for Determining the first left position of element x in the lst list:
lst.insert(i, x)
lst.append(x)
lst.extend(t)
lst.pop(i)
lst.index(x)
Method for Deleting an element with the number i from the lst list:
lst.index(x)
lst.pop(i)
lst.insert(i, x)
lst.append(x)
lst.extend(t)
Python. Method for removing the element x from the list lst at the first position on the left (Метод для Удаления элемента x в списке lst в первой слева позиции):
lst.sort()
lst.pop(i)
lst.index(x)
lst.remove(x)
lst.insert(i, x)
Python. Method for Sorting the list in ascending order (Метод для Сортировки списка по возрастанию):
lst.reverse()
lst.pop(i)
lst.sort()
lst.index(x)
lst.insert(i, x)
Python. A method that reverses the order of the list (Метод который меняет порядок списка на обратный):
lst.sort()
lst.pop(i)
lst.reverse()
lst.index(x)
lst.insert(i, x)
Python. A method that returns the number of elements in the list lst with the value x (Метод который возвращает количество элементов в списке lst с указанным значением):
lst.sort()
lst.pop(i)
lst.index(x)
lst.count(x)
lst.insert(i, x)
Python. Function for determining the length of a list (Определяется количество элементов списка):
append()
insert()
len()
reverse()
remove()
Python. Function for combining lists (Функция для объединения списков):
len()
lst1+lst2
insert()
reverse()
remove()
Method to Remove all elements from the list (Метод для удаления всех элементы из списка):
lst.sort()
lst.pop(i)
lst.clear(x)
lst.index(x)
lst.insert(i, x)
In the list lst = ["apple", "banana", "cherry"], print the last element of the list:
print (lst [0])
print (lst [1])
print (lst [-1])
print (lst [3])
print (lst [-2])
55. Python. There is a list lst = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] Print the elements: "cherry", "orange", "kiwi":
print (lst [-1])
print (lst [2:5])
print (lst [3:5])
print (lst [3:6])
print (lst [-2])
Python. Built-in function that converts object x to a list:
float(x)
tuple(x)
list(x)
int(x)
str(x)
Instruction for creating a multidimensional list of two elements, each of which is a list of three elements containing integer values (Инструкция по созданию многомерного списка из двух элементов, каждый из которых представляет собой список из трех элементов, содержащих целочисленные значения):
lst = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ]
lst = [ 'January' , 'February' , 'March' ], 3
print (lst[0] )
print ( '\nTop Left 0,0 :' , lst[1][0] )
max(lst)
Instructions for printing the values of a two-dimensional list (Инструкция для печати значений двумерного списка):
print(lst[0] )
print ('\nTop Left 0,0 :', lst[1][0] )
print(lst[0] )
max(lst)
59. Instruction for finding a slice of a list (среза списка) containing elements of the list with numbers from i to j with step k (Инструкция для нахождения среза списка, содержащего элементы списка с номерами от i до j с шагом k):
list = [ 'January', 'February', 'March' ],3
print(lst[0] )
print ('\nTop Left 0,0 :', lst[1][0] )
list = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ]
lst[i:j:k]
Operation to find a slice (среза) of a list lst:
lst[i:j:k]
len (lst)
lst * n
del lst [i]
del lst [i:j]
The result of the program: n=5 b = [0 for i in range (n - 1)] print (b)
{2, 4, 6, 8}
[0, 0, 0, 0]
[0, 1, 2, 3]
A block of code that runs only when called to solve a specific task:
Выражение (expression)
Функция (Function)
Выявление ошибки (raise an error)
Глобальный код (global code)
Идентификатор (identifier)
Definition of the Function (Определение функции):
tuple
set
def
dictionary
boolean
Calling a function with arguments (Вызов функции с аргументами): def my_function(fname): print(fname + ' Refsnes')
my_func ()
my_function()
my_function('Emil')
my_func1('python')
func ()
Function result (Результат функции): def f(x): x = 2**x+4*x return x print (f(2))
8
4
12
16
88
66. Local variable of the Function (Локальная переменная функции) is:
A variable declared inside a function and accessible only within itThe value of the variable is assigned inside the functions (Значение переменной присваивается внутри функций)
A variable declared outside any functionA variable created outside of a function (if it is visible throughout the program) (Переменная, создаваемая вне функции (если она видна во всей программе))
Positional arguments (Позиционные аргументы)
Named arguments (Именованные аргументы)
Argument (Аргумент)
67. Global variable of the Function (Глобальная переменная функции):
A variable created outside of a function (if it is visible throughout the program) (Переменная, создаваемая вне функции (если она видна во всей программе))
Positional arguments (Позиционные аргументы)
Named arguments (Именованные аргументы)
Argument (Аргумент)
The value of the variable is assigned inside the functions (Значение переменной присваивается внутри функций)
The arguments of the function are specified in the order exactly corresponding to the order in which the parameters are written.
Named arguments (Именованные аргументы)
Positional arguments (Позиционные аргументы)
A variable created outside of a function (it is visible throughout the program) (Переменная, создаваемая вне функции, видима во всей программе)
The value of the variable is assigned inside the functions (Значение переменной присваивается внутри функции)
Argument (Аргумент)
The result of a function with a list as an named argument: Code: def my_function(food): for x in food: print(x) lst = [1, 2, 3] my_function(lst)
6
1 2 3
12
The result of a function with a default parameter: def summa(x, y=2): return x + y a = summa(3) print(a)
3
2
4
5
6
The result of a function with a default parameter: def summa(x, y=2): return x + y b = summa(10, 40) print(b)
12
42
50
4
62
Operator for returning function values (Оператор для возвращения значений функции):
def
return
tuple
global
dictionary
Definition of an anonymous function (Определение анонимной функции):
return
lambda
def
global
dictionary
The result of the function: x = lambda a, b: a * b print(x(5, 6))
30
5
6
11
35
The result of the function: triple = lambda x: x * 3; add = lambda x, y: x + y; print(add(triple(3), 4))
12
13
6
11
35
Instructions for creating (packing- упаковки) a tuple:
list = [ 'January' , 'February' , 'March' ] ,3
printf('\nTop Left 0,0 :' , list[1][0] )
colors-tuple = ('Red', 'Green', 'Red', 'Blue', 'Red')
list = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ]
len (list)
An ordered and immutable collection of data (Упорядоченная и неизменяемая коллекция данных):
dictionary
string
tuple
float
operator
78. Python. Data type – tuple (кортеж):
key()
del
pop()
remove()
Python. Program result: a = (10, 12, 50, 10, 2, 4, 15) print(a[2:5])
[50, 10, 2]
{50, 10}
(50, 10)
(12, 50, 10, 2)
(50, 10, 2)
Python. Program result: a = (10, 12, 50, 10, 2, 4, 15) print(a[3:])
[50, 10, 2, 4]
(10, 2, 4, 15)
{50, 10}
(50, 10, 2)
Python. Insert the required operator to print out all the elements of the tuple: a = (20, 10, 30) for i in ____________: print(a[i])
range(len(a))
range(1:6)
len(a)
range(len(turple))
(50, 10, 2)
Set of Python:
a = 154.02
a = 'Red'
a = {'Alpha', 'Bravo', 'Charlie'}
a = [20, 61, 2, 37, 4, 55, 36, 7, 18, 39]
a = ('Red', 'Green', 'Red', 'Blue', 'Red')
The result of the program chars = ['A', 'B', 'C'] for i in enumerate(chars): print(i, end = ' ')
A B C
(0, 'A') (1, 'B') (2, 'C')
0 1 2
10
25
The result of the program: a = set([3, 6, 3, 5]) print(a)
{2, 4, 6, 8}
{3, 5, 6}
[2, 3]
['П', 'Р', 'И', 'B', 'E', 'T', '!']
{3, 6, 3, 5}
86. Instructions for creating a set:
phonetic-set = { 'Alpha' , 'Bravo' , 'Charlie' }
list = [ 'January' , 'February' , 'March' ] ,3
colors-tuple = ( 'Red' , 'Green' , 'Red' , 'Blue' , 'Red' )
list = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ]
len (list)
A set method that returns elements from the set set1 that are not in set2 (разность множеств set1 - set2):
set.add(x)
set1.difference(set2)
set.update(x, y, z)
set.pop()
set1.intersection(set2)
Definition of a set:
color
pr = (200, 50)
s1 = {'cat': 'кошка', 'dog': 'собака', 'mouse': 'мышь'}
s2 = {3, 6, 3, 5}
[2, 3]
The result of the program: s1=set(range(5)) s1.add('5') print(s1)
A) {0, 1, 2, 3, 4, 5}
B) {0, 1, 2, 3, 4, '5'}
C) {'cat': 'кошка', 'dog': 'собака', 'mouse': 'мышь'}
D) {3, 5, 6, 7}
E) {7, 3, 6, 3, 7, 5}
The result of the program: s1=set(range(5)) s2=set(range(2)) s1.add('5') s3 = s1.intersection(s2) print(s3)
{0, 1}
{0, 1, 2, 3, 4, '5'}
{200, 50}
{'cat': 'кошка', 'dog': 'собака', 'mouse': 'мышь'}
The result of the program: s1=set(range(5)) s2=set(range(2)) s1.add('5') s3 = s1.union(s2) print(s3)
{0, 1, 2, 3, 4, 5}
{200, 50}
{0, 1, 2, 3, 4, '5'}
{'cat': 'кошка', 'dog': 'собака', 'mouse': 'мышь'}
{0, 1}
90. Python. Имеется кортеж . my_tuple = (4, 2, 3, [6, 5])
Какое действие приведет к ошибке:
del my_tuple[3]
my_tuple[3][0] = 9
del my_tuple
print(my_tuple[:])
print(my_tuple[-1])
91. Method to merge two sets and returns a new set (Метод объединяет два множества и возвращает новое множество):
set.update (x, y, z)
set.add (x)
set.pop ()
set1.union(set2)
set1.difference(set2)
92. A container that can contain multiple data elements as unique key and associated with it some value «key: value»:
turple
dictionary
string
float
operator
93. A function that returns an empty dictionary (Функция, которая возвращает пустой словарь):
list()
turple()
dict()
set()
type()
94. A dictionary method that returns a representation of all pairs (key, value) in dictionary d:
d.keys()
d.items()
set.pop ()
set1.difference (set2)
d.pop(k)
95. The result of the program: adding an element to the dictionary using a new index key and assigning a value to it (Результат программы: добавление элемента в словарь с помощью нового ключа индекса и присвоения ему значения)
{'brand': 'Форд', 'model': 'Мустанг', 'year': 1964}
{'brand': 'Форд', 'model': 'Мустанг', 'year': 1964, 'color': 'красный'
('brand': 'Форд', 'model': 'Мустанг', 'year': 1964)
> ['brand': 'Форд', 'model': 'Мустанг', 'year': 1964, 'color': 'красный']
{'color': 'красный'}
96. Method for deleting an element from the dictionary with the specified key name (Метод удаления элемента из словаря с указанным именем ключа):
update()
pop()
popitem()
del
clear()
97. Method for the method for returning dictionary keys (Метод для возвращения ключей словаря):
pop()
keys()
update()
popitem()
del
98. A method that returns a dictionary with the specified keys and value (Метод, который возвращает словарь с указанными ключами и значением):
99. A method that returns an element with the key «key» (Метод, который возвращает элемент с ключом “key»):
keys()
get(key)
update()
popitem()
values()
100. Output the value of the "model" key of the car dictionary using the get method (Вывести значение ключа "model" словаря car используя метод get):
car.get ("model")
get("model")
key. get("model")
pop(car)
remove()
