First
This commit is contained in:
11
Acara-12/NastedTuple.py
Executable file
11
Acara-12/NastedTuple.py
Executable file
@@ -0,0 +1,11 @@
|
||||
tuple1 = (1,2,3)
|
||||
tuple2 = ('satu', 'dua', 'tiga')
|
||||
tuple3 = ('andi', 23,68.5)
|
||||
tuple4 = (tuple1, tuple2, tuple3)
|
||||
|
||||
print (tuple1)
|
||||
print (tuple2)
|
||||
print (tuple3)
|
||||
print (tuple4)
|
||||
print (tuple4[1][2])
|
||||
print (tuple4[2][0])
|
||||
4
Acara-12/PengulanganTuple.py
Executable file
4
Acara-12/PengulanganTuple.py
Executable file
@@ -0,0 +1,4 @@
|
||||
tupleBulan = ('Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni')
|
||||
for month in tupleBulan:
|
||||
print (month)
|
||||
|
||||
13
Acara-12/SequenceUnpacking.py
Executable file
13
Acara-12/SequenceUnpacking.py
Executable file
@@ -0,0 +1,13 @@
|
||||
def finchion1():
|
||||
tuple1 = (1, 2, 3)
|
||||
tuple2 = ('satu', 'dua', 'tiga')
|
||||
tuple3 = ('andi', 23, 68.5)
|
||||
tuple4 = (tuple1, tuple2, tuple3)
|
||||
|
||||
nama, usia, berat = tuple3
|
||||
|
||||
print ('nama : ', nama)
|
||||
print ('usia : ', usia)
|
||||
print ('berat : ', berat)
|
||||
|
||||
finchion1()
|
||||
16
Acara-12/slicing.py
Executable file
16
Acara-12/slicing.py
Executable file
@@ -0,0 +1,16 @@
|
||||
tupleAngka = 1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
#slicing tuple
|
||||
print (tupleAngka[0:3])
|
||||
print (tupleAngka[1:-1]) # memotong indeks ke 1 hinga -1
|
||||
print (tupleAngka[-1:1])
|
||||
print ('\n')
|
||||
|
||||
#slicing tanpa batas
|
||||
print (tupleAngka[2:])
|
||||
print (tupleAngka[5:])
|
||||
print (tupleAngka[8:])
|
||||
print (tupleAngka[:0])
|
||||
print (tupleAngka[:1])
|
||||
print (tupleAngka[:3])
|
||||
print (tupleAngka[:5])
|
||||
8
Acara-12/slicing3.py
Executable file
8
Acara-12/slicing3.py
Executable file
@@ -0,0 +1,8 @@
|
||||
tupleAngka = 1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
#Indeks kelipatan
|
||||
#dari awal sampai khir dengan kelipatan indeks 2 langkah
|
||||
print (tupleAngka[::2])
|
||||
|
||||
#dari indeks 1 hingga ke-8 dengan kelipatan indeks 3 langkah
|
||||
print (tupleAngka[1:8:3])
|
||||
4
Acara-12/slicing4.py
Executable file
4
Acara-12/slicing4.py
Executable file
@@ -0,0 +1,4 @@
|
||||
tupleAngka = 1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
#mencoba mengubah tuple indeks ke 0 dari angka 1 menjadi angka 0
|
||||
tupleAngka[0] = 0
|
||||
23
Acara-12/tuple.py
Executable file
23
Acara-12/tuple.py
Executable file
@@ -0,0 +1,23 @@
|
||||
tupleKosong = ()
|
||||
tupleSingleton = ('satu',)
|
||||
tupleSingleton2 = (1,)
|
||||
tupleSingleton3 = 'satu',
|
||||
tupleBulan = ('Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni')
|
||||
|
||||
#dibuat tanpa kurung
|
||||
tupleAngka = 1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
print (tupleKosong)
|
||||
print (tupleSingleton)
|
||||
print (tupleSingleton2)
|
||||
print (tupleSingleton3)
|
||||
print (tupleBulan)
|
||||
print (tupleAngka)
|
||||
print ('\n')
|
||||
|
||||
#cek tipe data
|
||||
|
||||
print (type(tupleSingleton))
|
||||
print (type(tupleSingleton2))
|
||||
print (type(tupleSingleton3))
|
||||
print (type(tupleAngka))
|
||||
20
Acara-12/tuple2.py
Executable file
20
Acara-12/tuple2.py
Executable file
@@ -0,0 +1,20 @@
|
||||
tupleKosong = ()
|
||||
tupleSingleton = ('satu',)
|
||||
tupleSingleton2 = (1,)
|
||||
tupleSingleton3 = 'satu',
|
||||
tupleBulan = ('Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni')
|
||||
|
||||
#dibuat tanpa kurung
|
||||
tupleAngka = 1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
# menggabungkan 2 tuple menjadi 1
|
||||
tupleGab = tupleSingleton3 + tupleAngka
|
||||
print (tupleGab)
|
||||
|
||||
#mengakses data tuple
|
||||
print (tupleBulan[0])
|
||||
print (tupleBulan[3])
|
||||
print (tupleBulan[5])
|
||||
print (tupleAngka[-1])
|
||||
print (tupleAngka[-3])
|
||||
print (tupleAngka[-5])
|
||||
8
Acara-12/tupleFunc.py
Executable file
8
Acara-12/tupleFunc.py
Executable file
@@ -0,0 +1,8 @@
|
||||
tuple1 = (1,2,3)
|
||||
tuple2 = ('satu', 'dua', 'tiga')
|
||||
tuple3 = ('andi', 23,68.5)
|
||||
tuple4 = (tuple1, tuple2, tuple3)
|
||||
|
||||
print (max(tuple1))
|
||||
print (min(tuple1))
|
||||
print (len(tuple1))
|
||||
Reference in New Issue
Block a user