- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
Latest commit
29 lines (25 loc) · 573 Bytes
/
Copy pathclasses.py
File metadata and controls
29 lines (25 loc) · 573 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
classmyclass:
x=5
y=10
kali=x*y
tambah=x+y
defmyclasses():
x=5
y=10
kali=x*y
tambah=x+y
returnx, y, kali, tambah
# Mendefinisikan 'Objek'
# 'Objek' adalah cetakan dari class, cetakan bisa lebih dari satu
p1=myclass()
p2=myclass()
# Untuk class, dapat memanggil variabel di dalam (tanpa return)
print(p1.x)
print(p1.y)
print(p1.kali)
print(p1.tambah)
# Untuk fungsi, harus ada return, tidak bisa memanggil variabel dalam
print(myclasses()[0])
print(myclasses()[1])
print(myclasses()[2])
print(myclasses()[3])