python - 与下面 Python 中的句子等效的代码是什么?

标签 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)

等同于:

if post_args is None:
    post_data = None 
else: 
    post_data = urllib.urlencode(post_args)

关于python - 与下面 Python 中的句子等效的代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6964194/

相关文章:

python - 是否可以在 Python 中重载对 vars(object) 的调用?

c++ - 如果他们的违规代码在 if(false) 中,我是否必须专门化模板

Python:查看列表中的哪些值 "if any"语句为 true

python - 检查 F 对象的结果是否大于零

c - 将乘法添加到 IF 语句

c++ - 知道为什么下面的代码片段打印 2 而不是 3

c++ - c 不匹配 if 的 else 是非法的

python - 遍历字典中的列表元素

python - 运行时错误 : working outside of application context

python - 如何减少拼接图像之间的颜色差异以实现平滑的颜色过渡?