The understanding and application of NULL without none True in Python

Source: Internet
Author: User

How do you often see these situations when you're making a judgment on python?


If True:

If s:

If key is not None:

If not s:



And so on that judgment


Understand

1 NULL is a data type of without as

S= "

L=[]

D = {}

t = ()

All of these represent no elements


In [Sat]: s= ' in []: ' If s: ....: print ' s string not empty ' ....: ' Else: ....: print ' s string is empty ' ....: s string is empty


Often, judging whether a string has a ' out of space ' or ' \ n ' element is commonly judged as follows

If S.strip (): Passelse:pass



2 None Type

None is a nonetype type, note is type

in [[]: A = Nonein []: Type (a) out[49]: Nonetypein [[]: Type (None) out[50]: Nonetype


in [+]: If A is not none: ....: print ' A not none ' ...: Else: ...: print ' None ' ....: none


Commonly used to determine whether an element is of type none

If A is not None:passelse:pass

None often appears in the default parameter assignment of the function Def f (s=none) and return value in the None




3 Boolean type True False

In [the]: if True: ....: print ' true ' ....: ' Else ' ...: print ' false ' ....: true


Common: return True of a function or if judgment


If True equals if not False

in [+]: not falseout[47]: True



4 Not for negate

Note that the counter can not be used!


If not s:










This article is from the "Tridewah operation and maintenance work Road" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1767091

The understanding and application of NULL without none True in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.