Professional Documents
Culture Documents
Konsep Pemrograman Data
Konsep Pemrograman Data
Konsep Pemrograman Data
to Programming
Ari Pratiwi
What is Programming?
(http://revolution.byu.edu/programmingconcepts/ControlStruct.php)
5
Identifiers
• A valid identifier is a sequence of one or more
letters, digits or underscore characters (_).
• Neither spaces nor punctuation marks or symbols
can be part of an identifier. Only letters, digits and
single underscore characters are valid.
• variable identifiers always have to begin with a
letter. They can also begin with an underline
character (_ ), but in some cases these may be
reserved for compiler specific keywords or external
identifiers, as well as identifiers containing two
successive underscore characters anywhere.
• In no case they can begin with a digit.
6
Data types
10 integer
5.23 float
9/18/18
Command on Python
command result
command Result
float(10)
int(5.23)
int(“2”)
float(“1.3”)
str (1)
str (2.3)
9/18/18
Command on Python
command result
command Result
float(10) 10.0
int(5.23) 5
int(“2”) 2
float(“1.3”) 1.3
str (1) ‘1’
str (2.3) ‘2.3’
9/18/18
Simple Type
Content Type
10 integer
5.23 float
9/18/18
Command on Python
command result
command Result
int(True) 1
int(False) 0
bool(1)
bool(0)
9/18/18
Command on Python
command result
command Result
int(True) 1
int(False) 0
bool(1) True
bool(0) False
9/18/18
Expressions
An expression is a sequence of operands and operators
that reduces to a single value.
14
Arithmetic operator
Operator Example Result
+ 2 + 3 5
- 4 - 8 -4
* 5 * 6 30
/ 6 / 2 3
5 / 3 1.666666666667
// 5 // 3 1
6 // 2 3
15
Variables
a) Variables are names for memory locations.
b) each memory location in a computer has an address.
c) A programmer can use a variable, such as score, to
store the integer value of a score received in a test.
d) Since a variable holds a data item, it has a type.
1
a
16
Command on Python
command result
A = 1 A
A 1
A = ‘1’
A ‘1’
A = 1 A
A 1
A = ‘1’
A ‘1’
X = X / 2
Y = 50 - X
9/18/18
String Operation
‘Kelas Python’ ‘24+4’ ‘Bahasa @laY’
command result
Str_var
K e l a s P y t h o n
0 1 2 3 4 5 6 7 8 9 10 11
command result
Str_var = ‘Kelas Python’
Str_var[0] ‘K’
Str_var[5] ‘ ‘
9/18/18
String Operation
Str_var
K e l a s P y t h o n
-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
command result
Str_var[-1] ‘n’
Str_var[-7] ‘ ‘
String Operation
Str_var
K e l a s P y t h o n
0 1 2 3 4 5 6 7 8 9 10 11
command result
Str_var[6:9] ‘Pyt’
Str_var[::2] ‘KlsPto ‘
Str_var[0:5:2] ‘Kls’
Command on Python
command result
len (Str_var) 12
3 * Str_var ‘Kelas PythonKelas PythonKelas Python’
Str_var = Str_var + ‘ seru!’ 'Kelas Python seru!'
x = Str_var.upper() 'KELAS PYTHON SERU!'
x
x = Str_var.replace(‘Python’,’BizDig’) 'Kelas BizDig seru!'
x
Str_var.find(‘as’) 3
Str_var.find(‘Biz’) -1
9/18/18