How to represent null values in python

First understand the concept of python objects

In Python, everything is an object, and all operations are directed to objects. What is an object? 5 is an int object,'oblong' is a str object, an exception is also an object, abstractly, human, cat, enough is also an object

For an object, it has two characteristics:

Properties: to describe its characteristics

Method: the behavior it has

Therefore, object = attribute + method (in fact, a method is also an attribute, a callable attribute that is different from the data attribute)

Class: Objects with the same attributes and methods can be classified into one category, namely class. Using one class can create multiple object instances, that is, humans, cats, and dogs belong to the mammalian class. A class is an abstraction of an object, and an object is an instantiation of a class. Class does not represent specific things, while objects represent specific things

Classes also have attributes and methods.

Data types are also objects

In fact, Pyhton only has the concept of object when designing object-oriented programming, and when designing process-oriented programming, data types are the most discussed.

The basic data types provided by Python mainly include: boolean, integer, floating point, string, list, tuple, set, dictionary, etc.

The entire data type can also be regarded as a "class". Each data type is an object and also has its own properties and methods.

Understand the above concepts, it is not difficult to understand the difference between None and Null

1 ) Are different data types

In[3]:type(None)
Out[3]: NoneType

Indicates that the value is an empty object, and the empty value is a special value in Python, represented by None. None cannot be understood as 0, because 0 is meaningful, and None is a special null value. You can assign None to any variable, and you can assign None to a variable

In[4]:type('')
Out[4]: str

Knowledge point expansion:

In Python, a series of objects representing null and nothing, such as None, empty list [], empty dictionary {}, empty tuple (), and 0, will be converted to False. All other objects will be converted to True. Python variables are initialized to empty values:

Value

digital_value = 0

String

str_value = “”

List

list_value = []

dictionary

ditc_value = {}

Tuple

tuple_value = ()

The built-in function any() used for judgment of empty types in Python,

any(iterable)
Return True if any element of the iterable is true. If the iterable is empty,return False. Equivalent to:
 
def any(iterable):for element in iterable:if element:return True
 return False
New in version 2.5.

So far, this article on how to represent empty values in python is introduced. For more related content on how to represent empty values in python, please search for the previous articles of ZaLou.Cn or continue to browse related articles below. Hope you will support ZaLou more in the future. Cn!

Recommended Posts

How to represent null values in python
How to represent relative path in python
How to wrap in python code
How to omit parentheses in Python
How to write classes in python
How to filter numbers in python
How to read Excel in Python
How to view errors in python
How to write return in python
How to understand variables in Python
How to clear variables in python
How to use SQLite in Python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How to save text files in python
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to write try statement in python
How to define private attributes in Python
How to add custom modules in Python
How to understand global variables in Python
How to view installed modules in python
How to open python in different systems
How to sort a dictionary in python
How to add background music in python
How to use the round function in python
How to use the zip function in Python
How to program based on interfaces in Python
How to install python in ubuntu server environment
How to simulate gravity in a Python game
How to use the format function in python
How to use code running assistant in python
How to set code auto prompt in python
Teach you how to write games in python
How to delete files and directories in python
How to install the downloaded module in python
How to write a confession program in python
How to perform continuous multiplication calculation in python
How to comment python code
How to learn python quickly
How to uninstall python plugin
How to understand the introduction of packages in Python
How to understand a list of numbers in python
Example of how to automatically download pictures in python
How to save IE as an attachment in python
How to understand python objects
How to use python tuples
How to create a Python virtual environment in Ubuntu 14.04
How to find the area of a circle in python
Do you still know how to draw cakes in python? ? ?
How to install Helm in Ubuntu
python how to view webpage code
How to use hanlp in ubuntu
How to use python thread pool
How to write python configuration file
How to install PHP7.4 in CentOS
How to save the python program
How to install mysql in Ubuntu 14.04