0% found this document useful (0 votes)
4 views14 pages

Lecture 2

The document discusses Python data types including numbers, strings, Booleans, None, and datetimes. It also covers comparison, assignment, membership, and identity operators as well as control flow statements like if, elif, and else.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
4 views14 pages

Lecture 2

The document discusses Python data types including numbers, strings, Booleans, None, and datetimes. It also covers comparison, assignment, membership, and identity operators as well as control flow statements like if, elif, and else.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

Datatypes and control Flow

© DATAPOT 2021
Summarize the Previous Lesson

1. Why python
2. Anaconda
3. Jupyter Notebook
4. Writing your first python program
Outline

1. Python standard data types


2. Control Flow introduction
Python standard data types

Data types

Numbers String Boolean None Dates


and times

float int
1. Boolean
► The two boolean values in Python are written as True and False.
Comparisons and other conditional expressions evaluate to either
True or False. Boolean values are combined with the and and or
keywords.
1. Boolean
► Convert other object to boolean

FALSE TRUE
bool('') bool('s')
bool(0) bool(1)
bool(0.0) bool(1.1)
bool([]) bool([1, 2])
bool(None)
…. ….
Arithmetic operators
Operator Description Example

+ Addition Adds values on either side of the operator. a + b = 30

- Subtraction Subtracts right hand operand from left hand operand. a – b = -10

* Multiplication Multiplies values on either side of the operator a * b = 200

/ Division Divides left hand operand by right hand operand b/a=2

% Modulus Divides left hand operand by right hand operand and returns b%a=0
remainder

** Exponent Performs exponential (power) calculation on operators a**b =10 to the power 20

// Floor Division - The division of operands where the result is the 9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -
quotient in which the digits after the decimal point are 11.0//3 = -4.0
removed. But if one of the operands is negative, the result is
floored, i.e., rounded away from zero (towards negative
infinity) −
Comparison operators
Operator Meaning Example
Greater that - True if left operand is
> x>y
greater than the right

Less that - True if left operand is less


< x<y
than the right

Equal to - True if both operands are


== x == y
equal

Not equal to - True if operands are not


!= x != y
equal

Greater than or equal to - True if left


>= operand is greater than or equal to x >= y
the right

Less than or equal to - True if left


<= operand is less than or equal to the x <= y
right
Assignment operators
Operator Example Equivalent to

= x=5 x=5

+= x += 5 x=x+5

-= x -= 5 x=x-5

*= x *= 5 x=x*5

/= x /= 5 x=x/5

%= x %= 5 x=x%5

//= x //= 5 x = x // 5

**= x **= 5 x = x ** 5

&= x &= 5 x=x&5

|= x |= 5 x=x|5

^= x ^= 5 x=x^5

>>= x >>= 5 x = x >> 5

<<= x <<= 5 x = x << 5


Membership and Identity operators

Operator Meaning Example

True if the operands are identical (refer


is x is True
to the same object)

True if the operands are not identical


is not x is not True
(do not refer to the same object)

True if value/variable is found in the


in 5 in x
sequence

True if value/variable is not found in the


not in 5 not in x
sequence
2. None

► The Python “null” value


3. Datetimes

► The datetime type combines the information stored in date and


time
Control Flow

► if statements:
► code blocks
► elif <cond.>:
► code blocks
► else:
► code blocks
Summarize

► Assign input value from keyboard


► Numbers operators
► String operators
► String slicing
► String format
► Boolean operator and convert other datatype to bool.
► If, elif, else statement.

You might also like