Home > Backend Development > Python Tutorial > python-ternary operations and lambda

python-ternary operations and lambda

巴扎黑
Release: 2016-12-03 09:13:27
Original
1014 people have browsed it

Ternary operation:

name = "GOGOGO" if True else "HAHA"
Copy after login

is equivalent to:

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

Execution result:

GOGOGO

lambda:

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

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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template