程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

In c/c++ and python programming, null and none cannot be distinguished clearly

編輯:Python

First say NULL:
NULL yes C/C++ Only some , stay Python There is no .
It's in C Null pointer in .
stay C++ Is compiled as an integer 0, If you want to in C++ Null pointer in , It can be used nullptr.
stay C++ The test code in is as follows :

#include <iostream>
int main()
{

int a = 5;
a = NULL;
char b = 70;
b = NULL;
int kkk = 999;// The function of this sentence is to set a breakpoint 
return 0;
}

The operation results are as follows :

Besides, None:
None yes Python There's only one of them ,C/C++ Not in China .
None It's the type NoneType A value of , in fact , type NoneType There is only one value , Namely None. Of course . stay Python in , Everything is object , You can also understand it as None For the class NoneType An object of .None The object is Python Automatically created when the interpreter starts , Destroy when the interpreter stops .

None Often used to indicate missing values .

None The features are as follows :

  • None No operations are supported ;
  • None Compared with any other data type, always return False;
  • None And 0、 An empty list 、 An empty string 、 Empty dictionaries are different , For example, an empty dictionary is the following case ;
  • Can be None Assign to any variable ;
  • None It's not like len,size Etc ;

Besides , Without value return Statement also returns None.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved