ropering / Study

0 stars 0 forks source link

[Python] 22.04.08 #27

Open ropering opened 2 years ago

ropering commented 2 years ago

TIL

examples

test = map(lambda x: x*x, [1,2,3,4,5])

test = filter(lambda x: x > 10, [10, 20, 30]

with open('a.txt') as file:
    lorem ipsum

Trick - Difference ways to test multiple flags at once in Python

x, y, z = 0, 1, 0

#1
if (x==1) or (y==1) or (z==1):
    return True

#2
if x or y or z:
     return True

#3
if 1 in (x, y, z):
    return True:

#4
for i in (x, y, z):
    if i == 1:    return True:

#5
if any((x, y, z)):
    return True: