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