The difference between null and void

And the difference in python None of Null

First, understand the concept of python objects

in python, all things are objects, all operations are targeted object. What is the object? 5 is an int target, 'oblong' is a str objects, the exception is an object that is abstract, people, cats, enough is also an object

For an object that, it has the feature comprises two aspects: 
properties: it is characterized to describe 
the method: it has the behavior 
so that the object attributes = + method (in fact, a method is also an attribute, the attribute data is distinguished from callable attributes)

Class: the objects have the same properties and methods can be classified as a class, that class. Use a class can create multiple object instances, that is, people, cats, dogs belong to the class of mammals. Class is an abstract object, the object class is instantiated. Category does not mean specific things, while objects represent specific things 

There is also a class properties and methods.

Data types are objects

In fact Pyhton in object-oriented programming, the objects will have this concept, and in the process-oriented programming model, we discuss the most is the data type.

Python provides basic data types are: Boolean, integer, floating point, strings, lists, tuples, sets, dictionaries and so on.

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

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

1) different data types

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

Indicates that the value is an empty object, a null value is a special value in Python, expressed None. None not be interpreted as 0, because 0 is meaningful, and None is a special null value. None can be assigned to any variable can also be assigned to the variable value None

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

Character

2) to determine when all is False, no print

a = None
if a:
    print(1)
    
b = ''
if b:
    print(1)

3) different attributes

Use dir () function returns the property list method. If the parameter method comprising dir (), which will be called. If the parameter does not include dir (), which will maximize the collection of parameter information.

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 " , " junction " , " Decimal " , " Digit " , " identifier " , " flower " , " Numeric " , " the sprintable " , " Space " , " Title " , " Tupper " , "join', ' Light ' , ' lower ' , ' lstrip ' , ' husband trans ' , ' partition ' , ' replace ' , ' rfind ' , ' RINDEX ' , ' rjust ' , ' rpartition ' , ' rsplit ' , ' rstrip ' , ' split ' ,'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

The difference between the empty string and NULL SQL table in what

For the novice SQL, NULL value of the concept is often confusing, and often think that NULL is the empty string '' the same thing. Not the case. For example, the following statement is completely different:    

1
2
mysql>  INSERT  INTO  my_table (phone)  VALUES  ( NULL );    
mysql>  INSERT  INTO  my_table (phone)  VALUES  ( '' );

 Average value of these two statements will be inserted phone (phone) column, but the first statement is inserted NULL value , the second statement is inserted into an empty string .

Meaning of the first case can be interpreted as "unknown phone number", the meaning of the second case may be interpreted as "the person no phone, so there is no phone number."  

 

  For NULL handling, may use the IS NULL and IS NOT NULL operators and the IFNULL () function . In SQL, NULL values compare with any other value (even NULL) will never be "true."

Expression that contains NULL always export the NULL value, unless and expression in the document about the operator's function in other provisions were made.

All of the following examples are listed Returns NULL:   

1
  mysql>  SELECT  NULL , 1+ NULL , CONCAT( 'Invisible' , NULL );

 If you plan to search the column value is NULL column, you can not use expr = NULL test.

The following statement does not return any rows, this is because, for any expression, expr = NULL is never "true":  

1
  mysql>  SELECT  FROM  my_table  WHERE  phone =  NULL ;

To find NULL value, you must use the IS NULL test.

 

In the following statement, introduced the NULL phone number and find the phone number of empty way:    

1
2
mysql>  SELECT  FROM  my_table  WHERE  phone  IS  NULL ;    
mysql>  SELECT  FROM  my_table  WHERE  phone =  '' ;

    If you are using MyISAM, InnoDB, BDB, or MEMORY storage engine, the index can be increased in a column may have NULL values.

As Otherwise, the index must be declared as NOT NULL, NULL and can not be inserted into the column.   

 

 When reading data LOAD DATA INFILE, empty or missing for a column, with the 'update them.

If you want a NULL value in a column, use \ N in the data file. In some cases, you can use the text of the word "NULL".

 

    Using DISTINCT, GROUP BY, or ORDER BY, all NULL values ​​are considered equivalent.    

    When using ORDER BY, NULL value will be displayed first, if you specify DESC descending order, a NULL value will be displayed last.

    For the polymerization (accumulated) function , such as COUNT (), MIN () and the SUM (), NULL value is ignored. The exception to this is COUNT (*), it counts line rather than a single column value.

For example, the following statement produces two counts. First, counting the number of rows in the table, followed by counting the number of non-NULL values ​​in the age column:   

1
  mysql>  SELECT  COUNT (*),  COUNT (age)  FROM  person;

   Special treatment for certain types of columns, MySQL will have a NULL value. If you insert NULL TIMESTAMP columns will insert the current date and time. If NULL into an integer column having attributes AUTO_INCREMENT, inserted in the next number in the sequence

 

Guess you like

Origin www.cnblogs.com/daofaziran/p/11030917.html