三、pythonプロセス制御文
3098 ワード
1.if分岐構造
完全なif論理構造文 if expression:
statement1
elif expression:
statement2
,..
else:
statementn
pass文:プレースホルダに相当し、何もしない if 1:
pass
else:
print(" ")
断言: # true,
# false, AssertionError
assert expression
2.循環構造
whileループ文 while test_expression:
body_statement
for-inサイクル
for in | | :# , key
statements
# :isinstance(element,type)
# element type
for式 #
expression for in ...
list1 = [1,2,3,4]
# : ,
list2 = [x**2 for x in list1 if x % 2 == 0]
print(list2)
# :[4,16]
if expression:
statement1
elif expression:
statement2
,..
else:
statementn
if 1:
pass
else:
print(" ")
# true,
# false, AssertionError
assert expression
whileループ文
while test_expression:
body_statement
for-inサイクル
for in | | :# , key
statements
# :isinstance(element,type)
# element type
for式
#
expression for in ...
list1 = [1,2,3,4]
# : ,
list2 = [x**2 for x in list1 if x % 2 == 0]
print(list2)
# :[4,16]