Python.exe-v/Python3-v
When installing Python3, you get an IDLE (prompt >>>), simple, useful, including syntax editor (variable color), debugging tools, Python shell, python3 online documentation.
Like Linux, you can press the TAB key to show a prompt
Python "as", \ Escape character
Introduction to the list
No variable identifier, subscript starting from 0
Movies = ["The Holy Gril",
"The Life of Brian",
"The Meaning of life"]
Print (movies[1]) # Result:the Life of Brian
The list has many representations of analog data structures, such as analog stacks
Append (): Add Append ("Gilliam") at the end of the list
Pop (): End of list delete data, Movies.pop ()
Extend (): In the list for the Insert collection, Movies.extend (["AAA", "BBB"])
Print (movie) # result:the Holy Gril, the life of Brian, the meaning of life, AAA, BBB
Remove (): Removes a specific data item from the list Movies.remove ("The Life of Brian")
Insert (): Add a data item Movies.insert (0, "xxx") before a specific location
A list can be stored together with different data types.
Movies = ["The Holy Gril", 1975,
"The Life of Brian", 1985
"The Meaning of Life", 1999]
Introduction to Loops
Movies = ["The Holy Gril",
"The Life of Brian",
"The Meaning of life"]
For Each_item in movies:
Print (Each_item)
Like other languages, Each_item does not have to be defined, note that there is a colon behind it:
The loop body uses an indent representation
Count = 0
While Count < Len (Movies):
Print (Movies[count])
Count = Count + 1
Multi-bit array nesting is supported, and print (movies[4][1][3]) has multiple layers [] brackets, so how does a multilayer list traverse?
We can also use the for each to traverse, but when traversing to a specific item, add an if to determine if the item itself is not a list,
The method used is that the isinstance () function is a BIF (build-in function) intrinsic.
Isinstance (Each_item, list) is used like this.
For Each_item in movies:
If Isinstance (Each_item, list):
For Nested_item in Each_item:
Print (Nested_item) # This layer can also continue to use if for judgment.
Else
Print (Each_item)
If there is a 5-level list, then our program is very ugly, this time we need a function to do something.
function
def function name ([optional parameter list]):
Function code Group
According to the above requirements, we define a function
def checklist (the_list):
For Each_item in The_list:
If Isinstance (Each_item, list):
Checklist (Each_item) # Here we use the recursive function
Else
Print (Each_item)
01 Initial python