python none
Python None关键字 (Python None keyword)
Note: None is not a keyword – we are just considering & writing it as a keyword which is a replacement of null (in C/C++).
注意: None不是关键字–我们只是考虑并将其编写为关键字,以替换null(在C / C ++中)。
"None" (case-sensitive) is an object of its own datatype, the NoneType, which is similar to null, it is used to define a null value to the variable or represents that a variable does not have any value at all.
“ None” (区分大小写)是其自己的数据类型对象, NoneType ,它类似于null,用于为变量定义一个null值或表示一个变量根本没有任何值。
None is a type of <class 'NoneType'>.
<class'NoneType'>的类型是None 。
Syntax:
句法:
None
Example:
例:
Input:
a = None
print("a: ", a);
Output:
a: None
Python code to demonstrate example of None keyword
Python代码演示None关键字示例
# python code to demonstrate example of
# None keyword
# type of None
print("type of None: ", type(None))
# declaring a variable and initialize it with None
a = None
# printing value
print("a: ", a)
# checkng None in condition
if a == None:
print("variable \'a\' contains None")
else:
print("variable \'a\' does not contain None")
# assigning a value and rechecking the condition
a = 100
if a == None:
print("variable \'a\' contains None")
else:
print("variable \'a\' does not contain None")
Output
输出量
type of None: <class 'NoneType'>
a: None
variable 'a' contains None
variable 'a' does not contain None
翻译自: https://www.includehelp.com/python/none-keyword-with-example.aspx
python none