Python pt.2
conditional statement and iteration statement
Python conditional statement
Literally, the conditional statement can be used in the conditions of data analysis on Python.
The reserved word of
conditional statement
isif/elif/else
.if
: The first condition is true.elif
: if not true in the first condition, but other conditions are true.else
: when every above conditions are falseFormat with example:
1
2
3
4
5
6if a > 15:
print('High')
elif a = 15:
print('Yes!')
else:
print('Low')Conditional statement is useful in various codes. (You’ll use it a lot!!)
Python iteration statement
- while:
- repeat infinitely not until the reserved word
break
is used (in other words, repeat until conditions are met) - format:
1
2
3while [conditions (able to be without conditions)]:
statement..
~ - if you stop the
while
statement because the conditions are alreay met, you have to use the reserved wordbreak
. - if you execute the statement and move on the next statement by passing only some specific condition, you can use the reserved word
continue
.
- for:
- repeat during the defined number of times
- use the
range
function withfor
loop (the automatically defined number of times) - format:
1
2
3for i in [list, tuple ...] (or range(#, #+1):
statement..
~