if python beginner Review

1 into the comparison operator type bool

Return result is True
This returns a value of True

printif grammar

num = 10
print("hello"  if num ==10 else "world")
print("hello"  if num ==5 else "world")
print("AAAA"  if bool(3) else "BBBB")
if  bool 为 True   ———>打印AAAA
bool为  Flase   ————> 打印BBBB


numif grammar

eg : 
 x = 10
 num = 10   if x>5    else  20 
 print(num)
>>>   10
if  x = 3
>>>  20
import os 
os.system("calc")  if   3>2   else os.system("notepad")
Published 25 original articles · won praise 3 · Views 503

Guess you like

Origin blog.csdn.net/qq_44045101/article/details/100850103