Lecture 2
Lecture 2
© DATAPOT 2021
Summarize the Previous Lesson
1. Why python
2. Anaconda
3. Jupyter Notebook
4. Writing your first python program
Outline
Data types
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
- Subtraction Subtracts right hand operand from left hand operand. a – b = -10
% 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
= 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
► if statements:
► code blocks
► elif <cond.>:
► code blocks
► else:
► code blocks
Summarize