Example 1
empty = []
Print Empty.append ("Hi")
Output None
Print empty
Output ["Hi"]
Error: Direct print variable with append ()
----------------------------------------------------------------------
Example 2
Print [].append ("Hi")
Output None
Error: Direct Print list with append ()
----------------------------------------------------------------------
Example 3
List = [].append ("Hi")
Print List
Output None
Error: Print variable directly, but variable is list with append ()
-----------------------------------------------------------------------
Next, let's check it out.
empty = []
Print type (empty.append (' Hi '))
Output <type "nonetype>
Print ([].append (' Hi '))
Output <type "nonetype>
List = [].append ("Hi")
Print List
Output <type "Nonetype" >
list = []
List.append ("Hi")
Print List
Output ["Hi]
Print type (list)
Output <type "Nonetype" >
So, print prints the list on the output list, prints a list of Nonetype (with append ()
or a variable or a variable of itself containing append (), the output is None
Append () Common errors