You can use 'if' effectively to assign a value to a variable. See the following example:
The value of go_to_movie is set to Yes, if movie_is_harry_potter=True or else it will be set to 'No'.
Please note that movie_is_harry_potter takes either True / False but not any other value if you are planning to use it in the 'if' statement here.
go_to_movie = Yes if movie_is_harry_potter else No
print(go_to_movie)
The value of go_to_movie is set to Yes, if movie_is_harry_potter=True or else it will be set to 'No'.
Please note that movie_is_harry_potter takes either True / False but not any other value if you are planning to use it in the 'if' statement here.
No comments:
Post a Comment