简体   繁体   中英

How do I check whether a variable is declared in Python?

如何不使用tryexcept语句检查是否声明了变量?

The dir() command gives a list of all the variables in your global namespace. If your variable is x_val , use

'x_val' in dir()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM