Persiapan :
1. PC dengan OS windows/Linuk/MAC
2. Python terinstal
1. Buka python dan muncul aplikasi console seperti dibawah ini (masuk ke cmd command)
2. Ketik :
a=5 [enter]
b=3 [enter]
c=a+b [enter]
print(‘c= ‘,c) [enter]
Praktik 2.1 : Tipe Koleksi : Tipe Tuple (sama dengan list Dictionary, bedanya tidak dapat diubah)
Praktik 2.1 : Tipe Koleksi : Tipe Set (sama dengan list Dictionary, bedanya data unik, tidak bida ada data
sama)
>>> s=set([10,10,20,30,30,30])
>>> s
{10, 20, 30}
>>> len(s)
3
>>> s.add(6)
>>> s
{10, 20, 30, 6}
>>> s.add(20)
>>> s
{10, 20, 30, 6}
>>> len(s)
4
>>>
Setting the Data Type (Tabel ini contoh pratek di 1.3 ; 1.4 dan seterusnya.
In Python, the data type is set when you assign a value to a variable:
x = 20 int
x = 20.5 float
x = 1j complex
x = True bool
x = b"Hello" bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
If you want to specify the data type, you can use the following constructor functions:
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = range(6) range
x = bool(5) bool
x = bytes(5) bytes
x = memoryview(bytes(5)) memoryview