1. Algoritma dan Pemrograman

Tanpa algoritma tidak akan pernah ada program.

4. Variabel

name = "Lewandowski"
age = 19

6. Input and Output

# implementasi untuk input
nama = input("masukan nama: ")
umur = input("masukan umur: ")
# implementasi untuk menghasilkan output
print(f”nama: {nama} umur: {umur}”)

7. Built-In Data Type (int, float, str, bool)

Integer (bilangan bulat)

#integer
a = 35656222554887711
b = -35656222554887711
c = 0
d = 100_000_000
#bukan integer
e = 099
f = 100, 000, 000

Float (bilangan desimal)

#float
a = 20.5
b = 7.0
c = 10.35656222554887711
#float
a = 15e8
b = 3E89
c = -75.7e100

String (karakter)

#string
name = 'brawijaya'
age = "twenty"
status = """died"""
year = "2002"

#boolean
a = True
b = False

9. Operator di Python

Operator Aritmatika

>>> 10 + 10
20
>>> 7 - 5
2
>>> 5 * 5
25
>>> 10 - 9.5
0.5
>>> 10 + 5.0
15.0
>>> 50 / 20
2.5
>>> 50 // 20
2
>>> 4 ** 2
16
>>> 4 ^ 2
6
>>> 15 % 5
0
>>> 10 % 7
3
>>> (25 - 10 + 5) ** 2
400

Operator Perbandingan

>>> 10 == 10
True
>>> 7 != 10
True
>>> 20 < 15
False
>>> 20 >= 30
False
>>> 5 == 'five'
False
>>> 5 <= 'five'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<=' not supported between instances of 'int' and 'str'
>>> 6 > 3 > 10
False
>>> 5 > 10 > 3
False

Operator Logika

>>> x = True
>>> y = False
>>> x and Y
False
>>> x or y
True
>>> not x
False
>>> 5 > 10 and 10 == 10
False
>>> (True and False) or (5 < 10)
True

Operator Bitwise

#0 | 1 = 1
#1 | 0 = 1
#1 | 1 = 1
#0 | 0 = 0
>>> x = 2 #00000010
>>> y = 5 #00000101
>>> x | y
7 #00000111
#1 & 1 = 1
#0 & 0 = 0
#0 & 1 = 0
#1 & 0 = 0
>>> x = 3 #00000011
>>> y = 6 #00000110
>>> x & y
2 #00000010
>>> ~0 #00000000
-1 #-00000001
>>> ~1 #00000001
-2 #-00000010
#0 ^ 0 = 0
#1 ^ 1 = 0
#0 ^ 1 = 1
#1 ^ 0 = 1
>>> x = 4 #00000100
>>> y = 8 #00001000
>>> x ^ y
12 #00001100
>>> x = 4 #00000100
>>> x << 2
16
>>> y = 9 #00001001
>>> y << 2
2 #00000010

Operator Assignment

>>> count = 100
>>> count
100
>>> x = 10
>>> x += 5 #same as x = x + 5
>>> x
15
>>> y = 3
>>> y *= x
>>> y
45

Operator Membership

>>> letters = ['a', 'i', 'u', 'e', 'o']
>>> 'u' in letters
True
>>> 'a' not in letters
False
>>> num = 45
>>> 5 in num
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument of type 'int' is not iterable

Identity operators

>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> c = a
>>> a is b
False
>>> a is c
True
>>> a is not b
True

Daftar Pustaka:

--

--

More from Data Science Indonesia

A place to share and learn about anything related to Data Science curated by Data Science Indonesia members for Data Science People.

Get the Medium app

A writer who focuses on the topics of Python, Statistics, Machine Learning, and Deep Learning. LinkedIn: https://www.linkedin.com/in/dede-kurniawann/