02. Python Control Statements
1. Conditional Statement
1.1. if... elif... else
if conditional_statement: # if
<code_block>
elif conditional_statement_2: # else if
<code_block>
else: # else
<code_block>
1.2. Ternary Operators
true_value if condtional_statement else false_value
2. Loop Statement
2.1. while
while conditional_statement:
<code_block>
2.2. for
for temp_var in iterable_object:
<code_block>
2.2.1. Comprehension Expression
-
List Comprehension
[<expression> for temp_var in iterable_object (if conditional_statement)]
list(<expression> for temp_var in iterable_object (if conditional_statement))
-
Dict comprehension
{<expression1>: <expression2> for temp_var in iterable_object (if conditional_statement)}
dict(expression1>: <expression2> for temp_var in iterable_object (if conditional_statement))
-
Set comprehension
{<expression> for temp_var in iterable_object (if conditional_statement)}
set(<expression> for temp_var in iterable_object (if conditional_statement))
2.3. Loop Control Keyword
- break
- end a loop
- continue
- back to the beginning of the loop with the next element
- else:
- It runs when the loop is completed without break
while: ... else: <code_block>
이전 포스트
01. Python Datatypes & Operators
다음 포스트