From the original "Hello World", go to object-oriented, to look back and see if there is anything missing in the tutorial.
As we mentioned before, "Everything is Object". So let's take a deep look at this sentence.
Need to first introduce two built-in Functions dir () and help ()
Dir () is used to query all properties of a class or object, you can try
>>>print dir (list)
Help () to query the description of the document, you can try
>>>print Help (list)
(list is a python built-in class that corresponds to the lists we've explained earlier)
List is a class
On top and see, the table is a class that Python has already defined. When we create a new table, for example:
>>>N1 = [1,2,3,4,5]
In fact, N1 is an object of the class list.
To experiment with some list methods:
>>>print N1.count (5) # count, see how many of them in total 5
>>>print N1.index (3) # Query the subscript of the first 3 of the N1
>>>n1.append (6) # Add a new element at the end of N1 6
>>>n1.sort () # Sort the elements of N1
>>>print N1.pop () # Removes the last element from the N1 and returns the element.
>>>n1.remove (2) # Remove the first 2 from the N1
>>>n1.insert (0,9) # Insert 9 at position Subscript 0
In summary, list is a class. Each list belongs to that class.
The Python supplement has an appendix to the list of common methods.
Operator is a special method
When using Dir (list), you can see an attribute, which is __add__ (). From the formal perspective is a special method (underline, underline). Where is it special?
This method defines the meaning of the "+" operator for the list object, and the actions that occur when the two list objects are added together.
>>>print [+] + [4,5,5]
...
A big part of Python's strength is that he offers a lot of built-in. such as list tuple and so on, they are easy to use, in Python
Standard library, there are a number of objects that can be used for operating system interaction, Internet development, multi-threaded text processing. And on the basis of all these,
There are also many external libraries that define richer objects, such as Numpy,tkinter Django for scientific Computing, GUI development, web development libraries, and a wide variety of objects, and it's much easier for the average user to use these libraries than to start from scratch.
Summarize
Len () dir () help ()
The data structure list (list) is a class.
Operator is a method
Python Basics 10 Review