Home > Backend Development > PHP Tutorial > Introduction to Python's Determining Whether a Variable is Defined_PHP Tutorial

Introduction to Python's Determining Whether a Variable is Defined_PHP Tutorial

WBOY
Release: 2016-07-13 17:41:53
Original
957 people have browsed it

Need to determine whether the variable has been defined. This is an easy task in PHP. You can just use the isset function to determine the variables, but it doesn't seem to be that simple in Python. I googled it, but there were no good results, so I finally had to write one myself. This is done using try .. except ..else.

Imitates PHP and defines an isset function.
def isset(v):
try:
type (eval(v))
except:
return 0
else:
return 1
def isset(v):
try:
type (eval(v)) except:
return 0
else:
                                                                                                                                                                                                            🎜>
When determining whether a variable is defined, just call this function directly, but it should be noted that a string must be passed in. For example, when determining whether user_name is defined, you need to call
like this·········10········20·········30········ 40·········50·········60·········70········80·········90···· ····100·······110·······120·······130·······140·······15001.if isset( user_name ):
print user_name is defined
else
print user_name is not defined





http://www.bkjia.com/PHPjc/486102.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/486102.html

TechArticleNeeds to determine whether the variable has been defined. This is an easy task in PHP. You can just use the isset function to determine the variables, but it doesn't seem to be that simple in Python. ...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template