1.三元表达式:如果成立返回if前的内容,如果不成立返回else的内容 name=input('姓名>>: ') res='SB' if name == 'alex' else 'NB' print(res) 2.列表推导式:l=['egg'+str(i) for i in range(1,11)] print(l) 3.生成器表达式: l=('egg'+str(i) for i in range(1,11) if i >6) for i in l: print(i)…
三元表达式 三元表达式仅应用于: 1.条件成立返回一个值 2.条件不成立返回一个值 res = x if x>y else y print(res) name= input("姓名>>: ") res="sb" if name == "alex" else "nb" print(res) 函数的递归 函数的递归:函数递归调用,即在函数调用过程中, 又直接或间接的调用了函数本身. 直接调用 def foo():…
十三. Python基础(13)--生成器进阶 1 ● send()方法 generator.send(value) Resumes the execution, and "sends" a argument which becomes the result of the current yield expression in the generator function. The send() method, like __next__(), returns the next v…
十二. Python基础(12)--生成器 1 ● 可迭代对象(iterable) An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list, str, and tuple) and some non-sequence types like dict and file and objects of any clas…