Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ sidebar_label: Version Changelogs & Updates
- [File/Data Format ➜ JSON](/basic/json)
- [Date, Time, DateTime, Timezone](/basic/datetime-timezone)
- [DateTime ➜ Parsing & Formatting](/basic/datetime-parsing-formatting)
- Perbaikan kesalahan kode

#### ◉ General update

Expand Down
4 changes: 2 additions & 2 deletions docs/basic/class-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Car:

Pada contoh di atas, class `Car` memiliki tiga attribute: `name`, `manufacturer`, dan `year`. Nantinya, variabel objek yang dibuat dari class tersebut akan memiliki tiga atribut sesuai dengan yang dideklarasikan.

> Fungsi `__init__(self)` disebut dengan method konstruktor. Pembahasan detail mengenai konstruktor ada di chapter [Class ➜ Constructor](#)
> Fungsi `__init__(self)` disebut dengan method konstruktor. Pembahasan detail mengenai konstruktor ada di chapter [Class ➜ Constructor](/basic/class-constructor)

### ◉ Deklarasi class tanpa attribute

Expand Down Expand Up @@ -116,7 +116,7 @@ Sebelumnya, kita telah membuat class bernama `Car` yang memiliki 3 attribute:

Attribute sebenarnya ada 2 jenis, yaitu instance attribute dan class attribute. **Yang sedang kita pelajari di chapter ini adalah instance attribute.**

> Perbedaan mendetail antara instance attribute vs class attribute ada di chapter [Class ➜ Class Attribute & Method](#)
> Perbedaan mendetail antara instance attribute vs class attribute ada di chapter [Instance Attribute & Class Attribute](/basic/instance-attribute-class-attribute)

Cara deklarasi instance attribute mirip dengan deklarasi variabel, perbedaannya pada penulisannya diawali dengan `self.`. Selain itu deklarasinya harus berada di dalam body fungsi `__init__(self)`.

Expand Down
4 changes: 0 additions & 4 deletions docs/basic/cli-arguments-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ Output program:

- [File I/O](/basic/file)

### ◉ TBA

- Flag without value https://stackoverflow.com/questions/8259001/python-argparse-command-line-flags-without-arguments

### ◉ Referensi

- https://docs.python.org/3/library/argparse.html
Expand Down
4 changes: 0 additions & 4 deletions docs/basic/datetime-parsing-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ Tabel kode format sesuai C89 standard:

- [Date, Time, DateTime, Timezone](/basic/datetime-timezone)

### ◉ TBA

- Locale

### ◉ Referensi

- https://docs.python.org/3/library/datetime.html
Expand Down
4 changes: 0 additions & 4 deletions docs/basic/datetime-timezone.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,6 @@ print_dt(data_utc_tz)

- [DateTime ➜ Parsing & Formatting](/basic/datetime-parsing-formatting)

### ◉ TBA

- Locale

### ◉ Referensi

- https://docs.python.org/3/library/datetime.html
Expand Down
38 changes: 19 additions & 19 deletions docs/basic/dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Ada tips agar data dictionary yang di-print di console muncul dengan tampilan ya

![Python dictionary pretty print](img/dictionary-3.png)

> Lebih detailnya mengenai JSON dibahas di chapter [JSON](#)
> Lebih detailnya mengenai JSON dibahas di chapter [File/Data Format ➜ JSON](/basic/json)

## A.16.2. Inisialisasi dictionary

Expand All @@ -122,7 +122,7 @@ Pembuatan data dictionary bisa dilakukan menggunakan beberapa cara:

```python
profile = dict(
set="id",
identifier="set",
name="john wick",
hobbies=["playing with pencil"],
is_female=False,
Expand All @@ -133,7 +133,7 @@ Pembuatan data dictionary bisa dilakukan menggunakan beberapa cara:

```python
profile = dict([
('set', "id"),
('identifier', "set"),
('name', "john wick"),
('hobbies', ["playing with pencil"]),
('is_female', False)
Expand Down Expand Up @@ -186,44 +186,44 @@ profile = {
"name": "mario",
"hobbies": ("playing with luigi", "saving the mushroom kingdom"),
"is_female": False,
"affliations": [
"affiliations": [
{
"name": "luigi",
"affliation": "brother"
"affiliation": "brother"
},
{
"name": "mushroom kingdom",
"affliation": "protector"
"affiliation": "protector"
},
]
}

print("name:", profile["name"])
print("hobbies:", profile["hobbies"])
print("affliations:")
print("affiliations:")

for item in profile["affliations"]:
print(" ➜ %s (%s)" % (item["name"], item["affliation"]))
for item in profile["affiliations"]:
print(" ➜ %s (%s)" % (item["name"], item["affiliation"]))

# output ↓
#
# name: mario
# hobbies: ('playing with luigi', 'saving the mushroom kingdom')
# affliations:
# affiliations:
# ➜ luigi (brother)
# ➜ mushroom kingdom (protector)
```

Pada kode di atas, key `affliations` berisi list object dictionary.
Pada kode di atas, key `affiliations` berisi list object dictionary.

Contoh cara mengakses value nested item dictionary:

```python
value = profile["affliations"][0]["name"], profile["affliations"][0]["affliation"]
value = profile["affiliations"][0]["name"], profile["affiliations"][0]["affiliation"]
print(" ➜ %s (%s)" % (value))
# output ➜ luigi (brother)

value = profile["affliations"][1]["name"], profile["affliations"][1]["affliation"]
value = profile["affiliations"][1]["name"], profile["affiliations"][1]["affiliation"]
print(" ➜ %s (%s)" % (value))
# output ➜ mushroom kingdom (protector)
```
Expand All @@ -238,24 +238,24 @@ profile = {
"name": "mario",
"hobbies": ("playing with luigi", "saving the mushroom kingdom"),
"is_female": False,
"affliations": [
"affiliations": [
{
"name": "luigi",
"affliation": "brother"
"affiliation": "brother"
},
{
"name": "mushroom kingdom",
"affliation": "protector"
"affiliation": "protector"
},
]
}

print(profile["affliations"][0]["name"])
print(profile["affiliations"][0]["name"])
# output ➜ luigi

profile["affliations"][0]["name"] = "luigi steven"
profile["affiliations"][0]["name"] = "luigi steven"

print(profile["affliations"][0]["name"])
print(profile["affiliations"][0]["name"])
# output ➜ luigi steven
```

Expand Down
3 changes: 1 addition & 2 deletions docs/basic/docstring.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ class Quote:
print(quotes[i])
```

Coba sekarang
Output ketika di-hover:
Coba sekarang lihat output ketika di-hover:

![Python docstring](img/docstring-5.png)

Expand Down
6 changes: 1 addition & 5 deletions docs/basic/enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class City(Enum):
JAKARTA = 4

print(list(City))
# output ➜ [<City.MALANG: 1>, <City.SURABAYA: 2>, <City.YOGYAKARTA: 3>, <City.JAKARTA: 4>
# output ➜ [<City.MALANG: 1>, <City.SURABAYA: 2>, <City.YOGYAKARTA: 3>, <City.JAKARTA: 4>]
```

Nilai property enum bisa diisi dengan data apapun. Pada contoh di atas, nilai property enum `City` diisi dengan angka numerik.
Expand Down Expand Up @@ -225,10 +225,6 @@ for c in City:

- [Konstanta](/basic/konstanta)

### ◉ TBA

- `IntFlag` and `Flag` https://docs.python.org/3/howto/enum.html#intflag

### ◉ Referensi

- https://docs.python.org/3/library/enum.html
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/error-exception.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Output program:

![Python exception](img/error-exception-3.png)

Alternatif solusi lainnya untuk mengatasi exception adalah dengan pengaplikasian kombinasi keyword `try` dan `catch`. Lebih detailnya akan dibahas di chapter berikutnya, di chapter [Exception Handling (try, catch, finally)](#).
Alternatif solusi lainnya untuk mengatasi exception adalah dengan pengaplikasian kombinasi keyword `try` dan `catch`. Lebih detailnya akan dibahas di chapter berikutnya, di chapter [Exception Handling (try, except, else, finally)](/basic/exception-handling-try-except-else-finally).

## A.47.3. Throw exception

Expand Down
4 changes: 0 additions & 4 deletions docs/basic/exception-handling-try-except-else-finally.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,6 @@ Penjelasan alur program di atas:

- [Error & Exception](/basic/error-exception)

### ◉ TBA

- catch custom exception

### ◉ Referensi

- https://docs.python.org/3/library/exceptions.html
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/for-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ for i in range(5, -5, -1):

Perulangan menggunakan `for` bisa dilakukan pada beberapa jenis tipe data (seperti list, string, tuple, dan lainnya) caranya dengan langsung menuliskan saja variabel atau data tersebut pada statement `for`.

> Tipe data yang bisa digunakan pada keyword `for` bisasa disebut dengan tipe iterator. Lebih detailnya dibahas pada chapter [Iterator](#).
> Tipe data yang bisa digunakan pada keyword `for` bisasa disebut dengan tipe iterator. Lebih detailnya dibahas pada chapter [Iterable & Iterator](/basic/iterable-iterator).

Contoh penerapannya bisa dilihat di bawah ini:

Expand Down
4 changes: 0 additions & 4 deletions docs/basic/instance-attribute-class-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ print(f"Object book2 note: {book2.note}")
- [OOP ➜ Class & Object](/basic/class-object)
- [OOP ➜ Property Visibility](/basic/property-visibility)

### ◉ TBA

- list-type attribute behaviour on class attribute vs instance attribute

### ◉ Referensi

- https://docs.python.org/3/tutorial/classes.html
Expand Down
5 changes: 0 additions & 5 deletions docs/basic/instance-method.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,6 @@ Output program:
- [OOP ➜ Abstract Method](/basic/abstract-method)
- [OOP ➜ Data Class](/basic/dataclass)

### ◉ TBA

- method & lambda
- method & closure

### ◉ Referensi

- https://docs.python.org/3/tutorial/classes.html
Expand Down
28 changes: 14 additions & 14 deletions docs/basic/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ import json

data = {
'name': 'Maiev Shadowsong',
'affliations': ['Warden', 'Alliance']
'affiliations': ['Warden', 'Alliance']
}
jstr = json.dumps(data)
print(jstr)
# output ➜ {"name": "Maiev Shadowsong", "affliations": ["Warden", "Alliance"]}
# output ➜ {"name": "Maiev Shadowsong", "affiliations": ["Warden", "Alliance"]}
```

Contoh data lain dengan struktur list berisi elemen dictionary:
Expand Down Expand Up @@ -158,7 +158,7 @@ Proses decode data JSON string ke tipe data Python dilakukan menggunakan fungsi
```python
import json

jstr1 = '{ "name": "Maiev Shadowsong", "affliations": ["Warden", "Alliance"], "age": 10000, "active": true }'
jstr1 = '{ "name": "Maiev Shadowsong", "affiliations": ["Warden", "Alliance"], "age": 10000, "active": true }'
data1 = json.loads(jstr1)

print(f"type: {type(data1).__name__}")
Expand All @@ -169,7 +169,7 @@ for key in data1:
# output ↓
#
# name: Maiev Shadowsong
# affliations: ['Warden', 'Alliance']
# affiliations: ['Warden', 'Alliance']
# age: 10000
# active: True
```
Expand All @@ -180,11 +180,11 @@ Contoh lain operasi decode data JSON string berisi array object:
jstr2 = """
[{
"name": "Maiev Shadowsong",
"affliations": ["Warden", "Alliance"],
"affiliations": ["Warden", "Alliance"],
"age": 10000
}, {
"name": "Illidan Stormrage",
"affliations": ["Illidari", "Armies of Legionfall"],
"affiliations": ["Illidari", "Armies of Legionfall"],
"age": 15000
}]
"""
Expand All @@ -194,11 +194,11 @@ print(f"type: {type(data2).__name__}")
# output ➜ type: list

for row in data2:
print(f"-> name: {row["name"]}, afflications: {row["affliations"]}, age: {row["age"]}")
print(f"-> name: {row["name"]}, affiliations: {row["affiliations"]}, age: {row["age"]}")
# output ↓
#
# -> name: Maiev Shadowsong, afflications: ['Warden', 'Alliance'], age: 10000
# -> name: Illidan Stormrage, afflications: ['Illidari', 'Armies of Legionfall'], age: 15000
# -> name: Maiev Shadowsong, affiliations: ['Warden', 'Alliance'], age: 10000
# -> name: Illidan Stormrage, affiliations: ['Illidari', 'Armies of Legionfall'], age: 15000
```

### ◉ Menulis data JSON ke file
Expand All @@ -211,11 +211,11 @@ Penulisan data JSON ke file sangat mudah, dilakukan menggunakan teknik penulisan
jstr = """
[{
"name": "Maiev Shadowsong",
"affliations": ["Warden", "Alliance"],
"affiliations": ["Warden", "Alliance"],
"age": 10000
}, {
"name": "Illidan Stormrage",
"affliations": ["Illidari", "Armies of Legionfall"],
"affiliations": ["Illidari", "Armies of Legionfall"],
"age": 15000
}]
"""
Expand All @@ -233,7 +233,7 @@ Penulisan data JSON ke file sangat mudah, dilakukan menggunakan teknik penulisan

data = {
'name': 'Maiev Shadowsong',
'affliations': ['Warden', 'Alliance']
'affiliations': ['Warden', 'Alliance']
}
jstr = json.dumps(data)

Expand All @@ -250,7 +250,7 @@ Operasi baca JSON file dilakukan dengan membaca file seperti biasa lalu di-decod
Contoh penerapannya bisa dilihat pada program di bawah ini. Sebelumnya, pastikan untuk menyediakan sebuah file JSON untuk keperluan testing dengan nama `data.json`. Isi file tersebut dengan data JSON string berikut:

```json
{"name": "Maiev Shadowsong", "affliations": ["Warden", "Alliance"]}
{"name": "Maiev Shadowsong", "affiliations": ["Warden", "Alliance"]}
```

Lalu tulis kode berikut kemudian run:
Expand All @@ -267,7 +267,7 @@ for key in data:
# output ↓
#
# name: Maiev Shadowsong
# affliations: ['Warden', 'Alliance']
# affiliations: ['Warden', 'Alliance']
```

---
Expand Down
2 changes: 2 additions & 0 deletions docs/basic/konstanta.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Statement `from typing import Final` artinya adalah meng-import tipe `Final` dar

Tipe `Final` digunakan untuk menandai suatu variabel adalah tidak bisa diubah nilainya (konstanta). Cara penerapan `Final` bisa dengan dituliskan tipe data konstanta-nya secara eksplisit, atau boleh tidak ditentukan (tipe akan diidentifikasi oleh interpreter berdasarkan tipe data nilainya).

> **Catatan**: Perlu diketahui bahwa `Final` hanya memberikan informasi ke type checker (mypy/Pylance) bahwa suatu variabel bersifat konstan. Di runtime, Python tidak menghasilkan error jika nilai variabel yang ditandai `Final` diubah. Immutability hanya berlaku di level type checking, bukan runtime.

```python
# tipe konstanta PI tidak ditentukan secara explisit,
# melainkan didapat dari tipe data nilai
Expand Down
4 changes: 0 additions & 4 deletions docs/basic/list-comprehension.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ print(transposed)
- [List](/basic/list)
- [Generator & Yield](/basic/generator-yield)

### ◉ TBA

- Stack vs Queue

### ◉ Referensi

- https://docs.python.org/3/tutorial/datastructures.html
Expand Down
4 changes: 2 additions & 2 deletions docs/basic/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ matrix = [
]

for row in matrix:
for cel in row:
for cell in row:
print(cel, end=" ")
print()
```
Expand Down Expand Up @@ -376,7 +376,7 @@ x = list_3.pop(7)

![list python](img/list-2.png)

> - Lebih detailnya mengenai error dibahas pada chapter [Error](#)
> - Lebih detailnya mengenai error dibahas pada chapter [Error & Exception](/basic/error-exception)

Selain menggunakan method `pop()`, keyword `del` bisa difungsikan untuk hal yang sama, yaitu menghapus elemen tertentu. Contoh penerapannya:

Expand Down
Loading
Loading