Python Frequently Asked Questions, Release 3.9.5 17 2.2. Core Language (continues on next page) 2.2.15 What’s up with the comma operator’s precedence? 2.2.17 Is it possible to write obfuscated one-liners in Python? 2.2.16 Is there an equivalent of C’s “?:” ternary operator? Yes. Usually this is done by nesting$_{lambda}$within$_{lambda}$ . See the following three examples, due to Ulf Bartelt: Yes, there is. The syntax is as follows: However, this idiom is unsafe, as it can give wrong results when on_true has a false boolean value. Therefore, it is always better to use the$_{... if ... else ...}$ form. The same is true of the various assignment operators ( = , += etc). They are not truly operators but syntactic delimiters in assignment statements. Since the comma is not an operator, but a separator between expressions the above is evaluated as if you had entered: Comma is not an operator in Python. Consider this session: >>> "a" in "b","a" (False, 'a') ("a" in "b"),"a" not: "a" in ("b","a") Before this syntax was introduced in Python 2.5, a common idiom was to use logical operators: [expression] and [on_true] or [on_false] [on_true] if [expression] else [on_false] x, y=50 ,25 small=x if x <y else y from functoolsimport reduce # Primes < 1000 print(list(filter( None ,map( lambda y:y*reduce( lambda x,y:x *y!= 0, map( lambda x,y=y:y%x,range(2,int(pow(y, 0.5 )+1))), 1), range(2,1000 ))))) # First 10 Fibonacci numbers print(list(map( lambda x,f= lambda x,f:(f(x -1,f) +f(x-2,f)) if x>1 else 1: f(x,f), range(10 )))) # Mandelbrot set print(( lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce( lambda x,y:x +y,map( lambda y, Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L= lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM, Sx=Sx,Sy=Sy:reduce( lambda x,y:x +y,map( lambda x,xc =Ru,yc=yc,Ru=Ru,Ro=Ro, i=i,Sx=Sx,F= lambda xc,yc,x,y,k,f = lambda xc,yc,x,y,k,f:(k <=0) or (x*x+y*y >=4.0 ) or 1+f(xc,yc,x *x-y*y+xc,2.0 *x*y+yc,k-1,f):f(xc,yc,x,y,k,f): chr( 64 +F(Ru+x*(Ro-Ru)/Sx,yc, 0,0,i)), range(Sx))):L(Iu +y*(Io-Iu)/Sy), range(Sy ))))( -2.1 ,0.7 ,-1.2 ,1.2 ,30 ,80 ,24 )) # \___ ___/ \___ ___/ | | |__ lines on screen # V V | |______ columns on screen # | | |__________ maximum of "iterations"