Search This Blog

Sunday, March 16, 2014

Use 'if' to assign a Value

You can use 'if' effectively to assign a value to a variable. See the following example:

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