Data and Expessions
Data and Expessions
Expressions
SY 2020-2021 3rd Term
CS001L Computer Fundamentals and Programming 1
Laboratory
Objectives
This lesson aims to explain topics about Data
and Expressions composed of literals, variables,
identifiers, operators, expressions, and data
types.
Literals
A literal is a sequence of
one or more characters Types of Literals
that stands for itself. It is
a succinct and visible integers
way to write a value. Floating point
booleans
strings
Literals:
Numeric Literals
A numeric literal is a literal containing only the
digits 0–9, a sign character (+ or -) and a
possible decimal point.
Literals:
Limits of Range in Floating-Point
Representation
Arithmetic overflow occurs when a calculated
result is too large in magnitude to be represented.
ex. >>> 1.5e200 * 2.0e210
>>> inf
Arithmetic underflow occurs when a calculated
result is too small in magnitude to be represented.
ex. >>>1.0e2300 / 1.0e100
0.0
Literals:
String Literals
A string literal, or string, is a sequence of
characters denoted by a pair of matching
single or double (and sometimes triple) quotes
in Python.
Ex. 'Hello’
'Smith, John’
"Baltimore, Maryland 21210"
A string consisting of only a pair of matching quotes is called the
empty string.
Literals:
Control Characters
ex. 1
4 + 3 * 5 ➝ 4 + 15 ➝ 19
ex. 2
(4 + 3) * 5 ➝ 7 * 5 ➝ 35
ex. 3
4 + 2 ** 5 // 10 ➝ 4 + 32 // 10 ➝ 4 + 3 ➝ 7
Expressions and Data Types:
Operator Associativity
(a) (8 - 4) - 2 ➝ 4 - 2 ➝ 2 8 - (4 - 2) ➝ 8 - 2 ➝ 6
(b) (8 / 4) / 2 ➝ 2 / 2 ➝ 1 8 / (4 / 2) ➝ 8 / 2 ➝ 4
(c) 2 ** (3 ** 2) ➝ 512 (2 ** 3) ** 2 ➝ 64
Expressions and Data Types:
Data Types
Data Type
Approaches
Static Typing
Dynamic
Typing
Expressions and Data Types:
Mixed-Type Expressions
Thanks!