-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intro_and_Variable_Types.py
147 lines (127 loc) · 3.57 KB
/
Intro_and_Variable_Types.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Basic Syntax
print("Hello World")
print("Hello \nWorld!")
# Quotation in Python
a = 'Python'
b = " Programming"
c = """ is so freaking easy"""
sentence = a+b+c
print(sentence)
# Multiple Statement in a single line
x = "5"; y = " balon"; print(x+y)
# Parameters
tipe_data = ["Boolean","Float","Integer","String"]
print(tipe_data)
tipe_data = '\n'.join(tipe_data)
print("List setelah menggunakan .join untuk setiap item list:\n", tipe_data)
# Data Types
nama = "ibe"
type(nama)
suhu = -99
type(suhu)
suhu_matahari = 1000000000
type(suhu_matahari)
suhu_kutub = -4.6
type(suhu_kutub)
ibe_ganteng = True
type(ibe_ganteng)
ibe_jelek = False
type(ibe_jelek)
# Assigning Value to Variable
sumsang = 2500000 # Automatically Integer
Laptop = input("Masukkan harga laptop:") # Automatically String even the value is number
# >
type(Laptop)
Sensors = int(input("Masukkan harga sensor-sensor: "))
# >
type(Sensors)
mouse = 125000; type(mouse)
headphone = 250000.0; type(headphone)
Kopi_SBUX = "Mahal Banget Ngab";
type(Kopi_SBUX)
# Multiple Assignment
a,b,c = 69,68,67
x = y = z = 38000
# Standart Data Types
# There are several data types: Number, String, List, Tuple, Dictionary
# Number Consist of int, float, and complex
# Python String
sedotan = "Panjang Banget huehuehue "
print(sedotan) # Print complete List / sentence
print(sedotan[0]) # Print 1st index of List (1st char)
print(sedotan[4:9])
print(sedotan[7:])
print(sedotan[:12])
print(sedotan[-1])
print(sedotan + "dan bahannya stainless skill xixixi")
print(sedotan*2)
print("Nama gue %s umur gue %d" % ("siapa dah", 23))
# Python List
# Python Lists are similar to arrays in C programming
# all items can be different data type and can be updated
contoh_list = ["bisa string", 20, 90.0, True,'john', 'mayer']
print(contoh_list)
print(contoh_list[0]) # Print first list
print(contoh_list[2:5])
print(contoh_list[:4])
print(contoh_list[2:])
print(contoh_list*2)
print(contoh_list[-1])
# Python Tuple
# Just like list but can not be updated/changed
Contoh_Tuple = ("Contoh tuple", 20, 9.0, False)
print(Contoh_Tuple)
# sisanya kayak list dan string, gue males ngetiknya hehe
# Python Dictionary
dict = {}
print(dict)
dict['satu'] = "This is one's value"
dict[2] = "This is two's value"
print(dict)
print(dict.values())
print(dict.keys())
print(dict['satu']) # Print dict one's value
print(dict['2'])
Big_dict = {'nama': "Johny Deep", "code": 6969, 'dept': "Videos Engineer"}
# Example Dictionary
mobil = {'nama': 'Deep', 'harga' : 300000000, 'diskon': 2000000}
motor = {'nama' : 'KLZ', 'harga' : 30000000, 'diskon' : 1000000}
sepeda = {'nama' :'Polyglot', 'harga' : 3000000, 'diskon': 200000}
harga_mobil = mobil['harga'] - mobil['diskon']
harga_motor = motor['harga'] - motor['diskon']
harga_sepeda = sepeda['harga'] - sepeda['diskon']
total_harga = harga_motor + harga_mobil + harga_sepeda
total_pajak = total_harga * 0.05
print(total_harga + total_pajak)
# Python Set
contoh_set = {"baju", "kaos", "sempak", "celana"} # Mutable
contoh_frozen_set = ({"gope","seceng","goceng"}) # Immutable
# Data Conversion
Duit = "Goceng"
in_number = 5000
print(Duit + in_number) # Error
print(Duit + str(in_number)) # Change it to string
# Variable Global dan Lokal
# Lokal
x = 911
print(x)
def sebuah_fungsi():
# global x
x = "telpon polisi"
print(x)
sebuah_fungsi()
print(x)
# Global
x = 911
print(x)
def sebuah_fungsi():
global x
x = "telpon polisi"
print(x)
sebuah_fungsi()
print(x)
# Delete Variable
_easting = 213891
print(_easting)
del(_easting)
print(_easting)