anancds / document

MIT License
1 stars 0 forks source link

python条件与循环的复用 #85

Open anancds opened 4 years ago

anancds commented 4 years ago

expression1 if condition else expression2 for item in iterable 相当于:

for item in iterable: if condition: expression1 else: expression2

anancds commented 4 years ago

而如果没有 else 语句,则需要写成:expression for item in iterable if condition

anancds commented 4 years ago

[(xx, yy) for xx in x for yy in y if xx != yy] 相当于:

l = [] for xx in x: for yy in y: if xx != yy: l.append((xx, yy))