⊗pyPmCdCG 135 of 208 menu

Gruppering av villkor i Python

Även om operationen and har högre prioritet än or är det ofta bekvämare att använda grupperande runda parenteser för att explicit visa operationsprioritet:

tst = 3 if (tst > 0 and tst < 5) or (tst > 10 and tst < 20): print('+++') else: print('---')

Ange operationsprioritet i explicit form i koden nedan:

tst = 3 if tst > 5 and tst < 10 or tst == 20: print('+++') else: print('---')

Ange operationsprioritet i explicit form i koden nedan:

tst = 3 if tst > 5 and tst > 0 and tst < 3: print('+++') else: print('---')

Ange operationsprioritet i explicit form i koden nedan:

tst = 3 if tst == 9 and tst > 10 and tst < 20 or tst > 20 and tst < 30: print('+++') else: print('---')
hysvcskaaz