Ternary operations:
if + = = 2:p rint (True) Else:print (false) #等同于: print (True if 1+1==2 else False)
Basic syntax of the function Def XX ():
Define function # return AA return value # or pass nothing Returns # XX () Call function # The function has three different parameters: #------Normal parameter------def func (name): print (name) func (' Fanh Aibo ') #------Default parameters------def func2 (name,age=30):p rint (name,age) func2 (' Fanhaibo ') func2 (' Zhang San ', #) #------Dynamic Parameters------# * Argsdef func3 (*args):p rint (args) func3 (1) func3 (' Hello ') func3 (all in All) func3 ([]) func3 ({1: ' A ', 2: ' B '}) #**kwargs: Multiple elements can be passed in to key= valuedef Func4 (**kwargs):p rint (Kwargs) func4 (name= ' Fanhaibo ', age=30) #*args **kwargsdef Func5 (arg,* Args,**kwargs): #print (args) #print (Kwargs) print (Arg,args,kwargs) #把1传给arg, pass ' a ' B ' C ' as a tuple to args, name, Age passed to Kwargsfunc5 (1, ' A ', ' B ', ' C ', name= ' Fanhaibo ', age=30)
004--python ternary operations, Python functions