相关疑难解决方法(0)

Python中的null对象?

我如何在Python中引用null对象?

python null

1097
推荐指数
5
解决办法
146万
查看次数

Python无比较:我应该使用"是"还是==?

可能重复:
`==`运算符何时不等于`is`运算符?(蟒蛇)

我使用的是Python 2.x.

我比较时编辑给了我一个"警告"下划线my_var == None,但是当我使用时没有警告my_var is None.

我在Python shell中做了一个测试,并确定两者都是有效的语法,但我的编辑器似乎说这my_var is None是首选.

是这种情况,如果是这样,为什么?

python comparison nonetype

182
推荐指数
4
解决办法
11万
查看次数

什么是'NoneType'对象?

我在运行python脚本时收到此错误:

TypeError: cannot concatenate 'str' and 'NoneType' objects
Run Code Online (Sandbox Code Playgroud)

我很确定'str'意味着字符串,但我不知道'NoneType'对象是什么.我的脚本在第二行开始了,我知道第一行是有效的,因为来自该行的命令在我的asa中,正如我所期望的那样.起初我以为可能是因为我在send_command中使用变量和用户输入.

'CAPS'中的所有内容都是变量,'小写'中的所有内容都是从'parser.add_option'选项输入的.

我正在使用pexpect和optparse

send_command(child, SNMPGROUPCMD + group + V3PRIVCMD)
send_command(child, SNMPSRVUSRCMD + snmpuser + group + V3AUTHCMD + snmphmac + snmpauth + PRIVCMD + snmpencrypt + snmppriv)
Run Code Online (Sandbox Code Playgroud)

python null nonetype

67
推荐指数
5
解决办法
24万
查看次数

如何设置变量的默认值?

想象一下我在javascript中有以下代码

function test(string) {
    var string = string || 'defaultValue'
}
Run Code Online (Sandbox Code Playgroud)

启动可能未定义的变量的python 方法是什么?

javascript python undefined

9
推荐指数
2
解决办法
1万
查看次数

在python中确定变量的类型是NoneType

我想检查变量是否属于该NoneType类型.对于其他类型,我们可以做以下事情:

    type([])==list
Run Code Online (Sandbox Code Playgroud)

但是NoneType这种简单的方法是不可能的.也就是说,我们不能说type(None)==NoneType.还有另一种方法吗?为什么有些类型而不是其他类型可能?谢谢.

python types python-3.x nonetype

8
推荐指数
2
解决办法
2万
查看次数

Python布尔变量,True,False和None

I have a boolean variable named mapped_filter. If I am not wrong, this variable can hold 3 values, either True, False or None.

I want to differentiate each of the 3 possible values in an if statement. Is there a better way to achieve that than doing the following?

if mapped_filter:
    print("True")
elif mapped_filter == False:
    print("False")
else:
    print("None")
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
3919
查看次数

标签 统计

python ×6

nonetype ×3

null ×2

comparison ×1

javascript ×1

python-3.x ×1

types ×1

undefined ×1