-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtuple.py
More file actions
30 lines (30 loc) · 863 Bytes
/
Copy pathtuple.py
File metadata and controls
30 lines (30 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fruits = ("apple", "banana", "cherry")
print(fruits[0])
fruits = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(fruits[2:5])
print(fruits[:5])
print(fruits[2:])
#เพิ่มค่าในtuple
x = ("apple", "banana", "cherry")
y = list(x) #แปลงเป็นlistแล้วเก็บค่าเข้า y
y[1] = "kiwi"
x = tuple(y)#แปลงlistเป็นtupleแล้วกลับมาเก็บค่าที่x
print(x)
#ลบค่าในtuple
x = ("apple", "banana", "cherry")
y = list(x)
y.remove("apple")
x = tuple(y)
print(x)
#join
tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3)
x = range(3, 6)
for n in x:
print(n)
x = range(3, 20, 5)
for n in x:
print("rangeแบบstep2:",n)
#นายวิษณุ พรจริยธรรม เลขที่99