Home  >  Article  >  Backend Development  >  python-ternary operations and lambda

python-ternary operations and lambda

巴扎黑
巴扎黑Original
2016-12-03 09:13:27999browse

Ternary operation:

name = "GOGOGO" if True else "HAHA"

is equivalent to:

if True:  
name = "GOGOGO"  
else:  
name = "HAHA"  
  
print (name)

Execution result:

GOGOGO

lambda:

f2 = lambda a1,a2: a1+a2  
t = f2(1,2)  
print (t)

is equivalent to:

Python code

def f2(a1,a2):

return a1 +a2

t = f2(1,2)

lambda cannot be judged using if, else and other conditions


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python-file operationsNext article:python-file operations