python - How to use raw input to define a variable -



python - How to use raw input to define a variable -

here code:

adherent = "a person follows or upholds leader, cause, etc.; supporter; follower." word=raw_input("enter word: ") print word

when run code , input adherent, word adherent produced. how can have definition of adherent pop instead?

you can (should) utilize dictionary words mapped definitions:

>>> word_dct = {"adherent" : "a person follows or upholds leader, cause, etc.; supporter; follower."} >>> word=raw_input("enter word: ") come in word: adherent >>> word_dct[word] 'a person follows or upholds leader, cause, etc.; supporter; follower.' >>>

creating dynamic variables bad , potentially unsafe practice. not easy lose track of them, if utilize exec or eval create them, run risk of executing arbitrary code. see why should exec() , eval() avoided? more information. accessing locals or globals frowned upon in favor of using list or dictionary.

python variables raw-input

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -