Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下面的Python语句的等效代码是什么?_Python_If Statement - Fatal编程技术网

下面的Python语句的等效代码是什么?

下面的Python语句的等效代码是什么?,python,if-statement,Python,If Statement,我不明白这段代码到底是做什么的。有什么帮助吗 谢谢 post_data = None if post_args is None else urllib.urlencode(post_args) 相当于以下内容: post_data = None if post_args is None else urllib.urlencode(post_args) 相当于以下内容: post_data = None if post_args is None else urllib.urlencode(po

我不明白这段代码到底是做什么的。有什么帮助吗

谢谢

post_data = None if post_args is None else urllib.urlencode(post_args)
相当于以下内容:

post_data = None if post_args is None else urllib.urlencode(post_args)
相当于以下内容:

post_data = None if post_args is None else urllib.urlencode(post_args)
这是一个在Python2.5中引入的。(它真的应该在一条线上)

如果
post\u args为None
,则它会完全按照它的意思执行--
post\u data
None
,否则它会被分配
urllib.urlencode(post\u args)
的结果

一种更为冗长的写作方式是

if post_args is None:
    post_data = None 
else: 
    post_data = urllib.urlencode(post_args)
或者,使用:

这是一个在Python2.5中引入的。(它真的应该在一条线上)

如果
post\u args为None
,则它会完全按照它的意思执行--
post\u data
None
,否则它会被分配
urllib.urlencode(post\u args)
的结果

一种更为冗长的写作方式是

if post_args is None:
    post_data = None 
else: 
    post_data = urllib.urlencode(post_args)
或者,使用:


照原样读……;-)照原样读……;-)