Font size
WorksheetsPython_lecture_tuple and list
Total questions: 15
Worksheet time: 8mins
Python-dagi kortejlar o'zgaruvchan
False
True
Kortej(tuple)ni yaratish kodlarini tanlang
t=(1,2)
t=tuple(1,2)
t={1,2}
t=[1,2]
t=tuple([1,2])
dasturning natijasi
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
dasturning natijasi
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
Natija
(1, '2', 3, 4, 5)
<class 'tuple'>
(1, 2, 3, 4, 5)
<class 'list'>
list1=("Red","Green","Yellow","Orange","Black")
list1.append("Emerald blue")
print(list1)
("Red","Green","Yellow","Orange","Black","Emerald blue")
("Red","Green","Yellow","Orange","Black")
Error
None
list1 = "a", "b", "c", "d";
print(type(list1))
Syntax not correct
("a", "b", "c", "d")
<class 'tuple'>
<class 'list'>
Natijaga nima chiqadi?
list1=["Red","Green","Blue","Yellow"]
list1.append("Black")
print(list1)
<class 'list'>
['Red', 'Green', 'Blue', 'Yellow', 'Black']
['Black','Red', 'Green', 'Blue', 'Yellow' ]
AttributeError: 'tuple' object has no attribute 'append'
Natijaga nima chiqadi?
list1=['sam', "Pam", 12,44]
print(list1[-1])
12
sam
No such index in the list
44
Natijaga nima chiqadi?
tuple1=['sam', "Pam", 12,44]
print(type(tuple1))
<class 'list'>
<class 'tuple'>
Natijaga nima chiqadi?
var1=['sam', "Pam", 12,44]
var1[3]="Ram"
print(var1)
['sam', 'Pam', 12, 44]
['sam', 'Pam', 12, 'Ram']
It will give an error
['sam', 'Pam', 'Ram',44]
Ushbu dasturning natijasi ?
aList = [4, 8, 12, 16]
aList[1:4] = [20, 24, 28]
print(aList)
[4, 20, 24, 28, 8, 12, 16]
[4, 20, 24, 28]
Ushbu dasturning natijasi ?
list1= [1, 3, 2]
print(list1 * 2)
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
Bo`sh list yaratish :
fruitList = ""
fruitList = ["empty"]
fruitList == []
fruitList = []
Natija ?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
[‘ab’, ‘cd’].
[‘AB’, ‘CD’].
None of the above
[None, None]
