Variable Assignment Within IF statement

Let’s say variable A had a value of ‘apple’.

Can I assign a new value to A within an IF statement if conditions are met?

ex)

a = ‘apple’

if a == ‘apple’:
a = ‘banana’

Thank you for your help!

if you try that code, what happens?

Yes, this will work. You’re saying if a is equal to whatever is inputted then a will now be assigned to your new variable

1 Like