Anonymous functions, ternary expressions, list comprehensions

# import xpinyin 
# p=xpinyin.Pinyin()
# print(p.get_pinyin('on the sofa',''))

def say():
num1=1
num2=2
num3=3
return num1,num2,num3
res1, res2,res3=say() #Anonymous
function lambda, only used once
# res=lambda x:x+1 # The front is the return value, followed by the processing logic
# print(res(1))
import random
red_num=random.sample( range(1,34),6)
new_num=[str(num).zfill(2) for num in red_num]#List generation
l=[i for i in range(1,101,2)]#First loop, put i Put it in a list to generate odd numbers within 100, and exchange space for time
l=(i for i in range(1,101,2))# #If there
are () parentheses outside, it is not a list, it is a generator
# The generator generator saves memory than list. It calculates an element according to the rules every time it loops and puts it in memory
#list It puts all elements in memory
for i in l:
print(i)
a=1
b=2
c=a if a>b else b #ternary expression
print(l)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324637062&siteId=291194637