zoukankan      html  css  js  c++  java
  • Python中的None与 NULL(即空字符)的区别

    None是Python的特殊类型,NoneType对象,它只有一个值None.

    它不支持任何运算也没有任何内建方法。

    None和任何其他的数据类型比较永远返回False。

    None有自己的数据类型NoneType。

    可以将None复制给任何变量,但是不能创建其他NoneType对象。

    是一种数据类型:

    >>>type(None)
    <class 'NoneType'>
    

    表示该值是一个空对象,空值是Python里一个特殊的值,用None表示。None不能理解为0,因为0是有意义的,而None是一个特殊的空值。

    >>>type('')
    <class ''str'>
    

    可以将空值赋值给任何变量,可以将任何变量赋值给一个空值的对象

    判断的时候 均是False

    >>> ff = None
    >>> if ff:
        print('ff is define')
    

    执行结果:无打印!

    属性不同

    使用dir()函数返回参数的属性、方法列表。如果参数包含方法dir(),该方法将被调用。如果参数不包含dir(),该方法将最大限度地收集参数信息。

    >>> dir(None)
    ['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
    
    
    >>> dir('')
    ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
    
  • 相关阅读:
    linux systemctl 命令详解
    nginx 与 php-fpm 通信配置
    yum Install PHP 7 on CentOS 7 (英文-转载)
    解决在idea中创建spring boot项目start.spring.io初始化失败的问题
    MongoDB学习5:模型设计和设计模式
    MongoDB学习4:MongoDB复制集机制和原理,搭建复制集
    `curl -L` 解决 GitHub 的 raw.githubusercontent.com 无法连接问题
    用 Hugo 快速搭建博客
    针对多系统时间不一致
    kali 下的邮件发送工具 swaks
  • 原文地址:https://www.cnblogs.com/pinpin/p/10346029.html
Copyright © 2011-2022 走看看