python-3.xjupyter-notebookshorthand

short hend if_else not working with assignment operater


When i try short hend if_else stetment with assingment operater syntaxerror is happening.i want to result based on the condition.like if condition is true so print 1 otherwise 0.

a=100
b=20
c=1 if(a>b) else c=0
print(c)

expecting 1 or 0 based on the condition.


Solution

  • try

    a=100
    b=20
    c=1 if(a>b) else 0
    print(c)
    

    you do not have to redeclare that c = 0 after the else, if i am correct.