Tutorial Variabel dan Ekspresi Aritmatika Python, Belajar Python

 Variabel dan Ekspresi Aritmatika di PYTHON

Kali ini kita belajar bagaimana membuat ekspresi aritmatika didalam pemrograman python, langsung saja kita simak .

Tutorial Variabel dan Ekspresi Aritmetika Python, Belajar Python
Tutorial Variabel dan Ekspresi Aritmetika Python, Belajar Python




Program di bawah ini adalah contoh ekspresi variabel dan aritmetik. Ekspresi matematik biasa adalah + (pertambahan), - (pengurangan), : (pembagian), dan * (perkalian)


Python 3.7.3
Type "help", "copyright", "credits" or "license()" for more information.
>>> 4+5
9
>>> (50+40*6)/2
145.0
>>> 10/2
5.0
>>> 10-7
3 

Seperti dalam C = digunakan untuk persamaan

Python 3.7.3
Type "help", "copyright", "credits" or "license()" for more information.
>>> width = 50
>>> height = 10
>>> width * height
500

Dapat juga untuk operasi nilai desimal


Python 3.7.3 
Type "help", "copyright", "credits" or "license()" for more information.
>>> 10 * 3.15
31.5
>>> 3.14 * 7
21.98


Belajar Operator Dasar Python // Belajar Python

Belajar Operator Dasar Python // Belajar Python

Belajar Bahasa Pemrograman Python

#BelajarPython #TutorialPython #BahasaPython



Belajar Operator Dasar Python Belajar Python
Belajar Operator Dasar Python Belajar Python






1. Menjalankan Phyton 

Program python dijalankan oleh “Interpreter”.  Saat awal menjalankan python kita akan menjalankan mode interaktif yang dapat langsung dijalankan. Di bagian atas interpreter ada tulisan copyright dan di bawahnya ada tanda >>>


Python 2.4.1 (#2, Mar 31 2005 , 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "Hello World"
Hello World
>>>

Dengan mengetik kata-kata contohnya “Hello World” dan tekan enter program langsung dijalankan.

2. Operator-operator dasar Phyton

Operator perbandingan 

Operator perbandingan digunakan untuk membandingkan dua objek/elemen dalam bahasa pemrogaman


Comparison Meaning Notes
< strictly less than (1)
<= less than or equal to
> greater than or equal to
== equal to
!= or <> not equal to
is object identity (2)
is not negated object identity (2)

Boolean Operator  

Boolean operator menghasilkan ouput benar (True) atau (False), digunakan untuk mencari apakah objek yang diperbandingkan memenuhi operator Boolean. 

Value Or Operator Evaluates to Notes
build-in bool(expr) true if expr is true, False otherwise see True, False
None, numeric zeros, empty sequences and mapping consider False
all other consider True
not x True if x is False, else False
x or y if x is False then y, else x (1)
x and y if x is False then x, else xy/td> (1)

Operator bit 


Operation Result
~x the bits of x inverted
x^y bitwise exclusive or of x and y
x&y bitwise and of x and y
x|y bitwise or of x and y
x<<nshifted left by n bits
x>>n x shifted right by n bits

Operator Numerikal  

Operator numerical digunakan untuk mengoperasikan nilai-nilai dalam objek Phyton. Misalnya saja perkalian, pembagian, pertambahan dan lain-lain, daftar operator numerical adalah sebagai berikut :
Operation Result
abs(x) the absolute value of x
int(x) x converted to integer
long(x) x converted to long integer
float(x) x converted to floating point
-x x negated
+x x unchanged
x+y the sum of x and y
x-y difference of x and y
x*y product of x and y
x/y true division of x by y: 1/2 -> 0.5(1)
x//y floor division operator: 1//2 -> 0(1)
x%y x modulo y
divmod(x, y) the tuple (x//y, x%y)
x**y x to power y (the same as pow (x,y))

Result Simillar :