Python clever use of a short-circuit or logic.

Short-circuit logic in Python I know a bit about that and when met after the first parameter is not judged Flase

Similarly or just against the first true, nor does it judged.

All or just interesting, directly on the test code

In [147]: name = input('wirte you name: ') or "shagua"                                                
wirte you name: 

In [148]: name                                                                                        
Out[148]: 'shagua'

In [149]: name = input('wirte you name: ') or "shagua"                                                
wirte you name: sidian

In [150]: name                                                                                        
Out[150]: 'sidian'

 Used to determine whether the input is empty, and then to the default parameters, feeling than writing function if forced to engage in grid five times

Guess you like

Origin www.cnblogs.com/sidianok/p/11780439.html