Konsep Pemrograman Data

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Introduction

to Programming

Ari Pratiwi
What is Programming?
(http://revolution.byu.edu/programmingconcepts/ControlStruct.php)

Programming means creating a set of


instructions for completing some specific task.
In this sense, many of our daily activities can
be described as programmatic—they involve
specific steps that often follow a set order

In the context of computing, programming


means creating a set of instructions not for a
person but for a computer, in order to
accomplish a specific task
Usually a set of instructions, or program, for a
computer is intended to complete a task that:
– is repetitious, and therefore would exceed human
patience or capacity for long term attention to
detail;
– controls machinery in conditions unsuitable for
humans because of physical limitations,
hazardous conditions, etc.;
– requires a high degree of accuracy;
– requires high speed.
Identifiers
a) identifier—that is, the name of objects.
b) each piece of data in a computer is stored at a
unique address.
c) to represent data locations symbolically

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

1) A data type defines a set of values and a set of


operations that can be applied to those values.
2) The set of values for each type is known as the
domain for the type.
3) Most languages define two categories of data types:
simple types and composite types.
a) A simple type is a data type that cannot be
broken into smaller data types.
b) A composite type is a set of elements in which
each element is a simple type or a composite
type.
7
Simple Type
Content Type

10 integer

5.23 float

“Halo there” string

9/18/18
Command on Python
command result

type (10) <class ‘int’>

type (5.23) <class ‘float’>

type(“Halo there”) <class ‘str’>

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

type (10) <class ‘int’>

type (5.23) <class ‘float’>

type(“Halo there”) <class ‘str’>

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

“Halo there” string

True, False boolean

9/18/18
Command on Python
command result

type (True) <class ‘bool’>

type (Falsse) <class ‘bool’>

command Result
int(True) 1
int(False) 0
bool(1)
bool(0)

9/18/18
Command on Python
command result

type (True) <class ‘bool’>

type (Falsse) <class ‘bool’>

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.

An operator is a language-specific token that requires


an action to be taken.

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

Priority: (), *,/ then +/ -

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’

command Value of A Type of A


A = 3 + 4
A = 6 / 2
A = 10
A = A // 2
A = ‘Halo’+’There’
9/18/18
Command on Python
command result

A = 1 A

A 1

A = ‘1’

A ‘1’

command Value of A Type of A


A = 3 + 4 7 int
A = 6 / 2 3.0 float
A = 10 5 int
A = A // 2
A = ‘Halo’+’There’ ‘HaloThere’ str
9/18/18
Contoh Soal
X = 30
Y = 50 – X

Berapakah nilai X dan Y dan tipe data masing-masing?

X = X / 2
Y = 50 - X

Berapakah nilai X dan Y dan tipe data masing-masing?

9/18/18
String Operation
‘Kelas Python’ ‘24+4’ ‘Bahasa @laY’

command result

Str_var = ‘Kelas Python’

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 [0:3] ‘Kel’

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

You might also like