Python overall understanding, python overall
As a script, python has the flexibility and convenience of a weak type language. This can greatly reduce the coding burden of developers in daily development and use, and developers can also focus on the logic Management of programs and the overall architecture design. In general, with the accumulation of experience, developers can use python to write beautiful code, concise and beautiful.
Python is also rigorous. From the predefined errors, we can find that python has a strict logical structure of the compilation language. In this case, with a deep understanding of python, you can feel that python still maintains the strict logic of the compilation language while providing various convenient operations, but it is much "hidden.
So what are the commendable features of python?
(1) python is strongly cohesive and can work with c, c ++, java, and so on.
This is a powerful feature not available in most other languages, which allows python to work with functional code in other languages in a better and more convenient way. Compile a language to accelerate the execution of a program.
(2) python provides cross-platform features and supports various general operations
The strength of python is closely related to its cross-platform architecture. Now, apart from underlying development, it is difficult to popularize and expand a language or tool in the current environment if it cannot be used across platforms. Python's excellent background processing capabilities enable different platforms and tools to achieve the goal of writing and running everywhere in the same interface mode (of course, some must be adapted to the notes of various platforms ).
(3) It can also be said that python is an excellent software tool!
Python implements the core language through the C language, which includes the python interpreter. The interpreter is used to interpret text files that comply with the python syntax rules into commands that can be recognized by the python language, and then these commands are implemented through the python software. The core function of python is a software entity, and various functions of the software are presented in the text format specified by python. In large software, we control a lot of interface configuration and other functions through text configuration files, and python is undoubtedly doing better in this regard.
(4) Advantages of python syntax Design
Python has made bold development in terms of syntax design that is not available in other languages.
1. The role of python is not through curly braces and semicolons ending with indentation, which makes the overall code concise and small.
2. python implements a lot of syntax functions through dictionaries and classes, which makes many operations uniform. Although it is somewhat awkward to understand, it becomes abnormal and simple in terms of operations.
For example, namespace is implemented through dictionaries.
# Namespace scop;={}# preset variable code in the namespace, the value is namespaceconnoisseurs ['code'] = 'namespace' # the string is an executable python script pass # The code Sstring = "a = 12b = 'new' print ('Hello, world ') "pass # execute that string code and put it into the namespace scope exec (Sstring, scope)
Before executing the exec (Sstring, scope) line of code, the variable scope is a common dictionary, but after this line of code, scope is still a dictionary, however, there are many additional key values, which are obviously formatted as python namespaces by python.
Python implements namespaces through dictionaries to solve the problem of variable name contamination. It also provides basic and general dictionary methods such as dictionaries, which can be easily controlled by junior developers.
Of course, the solutions to variable name contamination that are not available in other languages are globals (), locals (), and nonlocals () functions. These functions provide all global variables, local variables, and external local variables in a dictionary. You have been impressed by the powerful capabilities of python.
The basic sequence and dictionary structure of python are actually python classes.
Python list [], tuples (), and dictionaries {} are actually classes.
1 >>> list.__bases__ 2 (<class 'object'>,) 3 >>> tuple.__bases__ 4 (<class 'object'>,) 5 >>> dict.__bases__ 6 (<class 'object'>,) 7 >>> object 8 <class 'object'> 9 >>> object.__bases__10 ()11 >>> help(object)12 Help on class object in module builtins:13 14 class object15 | The most base type
Through the above, we will find that in python, many basic things are implemented in the form of classes at the bottom layer of python. Therefore, many classes can use list, tuple, and dict as the base class. Objects are classes without base classes and pythond top-level superclasses.
In our list, as a class, the variable contained can be obtained through _ dict _.
1 >>> list.__dict__ 2 >>>{'__add__': <slot wrapper '__add__' of 'list' objects>, 3 '__contains__': <slot wrapper '__contains__' of 'list' objects>, 4 '__delitem__': <slot wrapper '__delitem__' of 'list' objects>, 5 '__doc__': 'list() -> new empty list\n' 6 'list(iterable) -> new list initialized from ' 7 "iterable's items", 8 '__eq__': <slot wrapper '__eq__' of 'list' objects>, 9 '__ge__': <slot wrapper '__ge__' of 'list' objects>,10 '__getattribute__': <slot wrapper '__getattribute__' of 'list' objects>,11 '__getitem__': <method '__getitem__' of 'list' objects>,12 '__gt__': <slot wrapper '__gt__' of 'list' objects>,13 '__hash__': None,14 '__iadd__': <slot wrapper '__iadd__' of 'list' objects>,15 '__imul__': <slot wrapper '__imul__' of 'list' objects>,16 '__init__': <slot wrapper '__init__' of 'list' objects>,17 '__iter__': <slot wrapper '__iter__' of 'list' objects>,18 '__le__': <slot wrapper '__le__' of 'list' objects>,19 '__len__': <slot wrapper '__len__' of 'list' objects>,20 '__lt__': <slot wrapper '__lt__' of 'list' objects>,21 '__mul__': <slot wrapper '__mul__' of 'list' objects>,22 '__ne__': <slot wrapper '__ne__' of 'list' objects>,23 '__new__': <built-in method __new__ of type object at 0x000000005BAFF530>,24 '__repr__': <slot wrapper '__repr__' of 'list' objects>,25 '__reversed__': <method '__reversed__' of 'list' objects>,26 '__rmul__': <slot wrapper '__rmul__' of 'list' objects>,27 '__setitem__': <slot wrapper '__setitem__' of 'list' objects>,28 '__sizeof__': <method '__sizeof__' of 'list' objects>,29 'append': <method 'append' of 'list' objects>,30 'clear': <method 'clear' of 'list' objects>,31 'copy': <method 'copy' of 'list' objects>,32 'count': <method 'count' of 'list' objects>,33 'extend': <method 'extend' of 'list' objects>,34 'index': <method 'index' of 'list' objects>,35 'insert': <method 'insert' of 'list' objects>,36 'pop': <method 'pop' of 'list' objects>,37 'remove': <method 'remove' of 'list' objects>,38 'reverse': <method 'reverse' of 'list' objects>,39 'sort': <method 'sort' of 'list' objects>}
We found that the append, clear, copy, count, extend, index, insert and other methods used in the list are all list-like object methods, the _ method added with double underscores is the "Private method" of the class. Many of these methods are commonly used for setatter operations, when getatter is used, python is the method that we automatically connect and call. To change the automatic functions of a custom class, you only need to rewrite these functions. Through square brackets [], the multipart value operation is _ getitem _.
1 >>> getattr(list,'append',None)2 <method 'append' of 'list' objects>
Classes, modules, and variables in python can be essentially attributed to functional address blocks (pointers) in memory)
These are the general methods of scripting language. The essence of a weak language is not to check and limit the type of the value, but to make it easy to use, the implicit conversion and memory pointer of this part of type conversion and type judgment have quietly done a lot of work behind us. It is precisely because all of them are pointers at the underlying layer that we can use the = symbol to assign values, reference functions (copy pointer addresses), and create objects (copy object addresses. Therefore, to understand the memory collection in python and the underlying functions, you must have a sufficient understanding of the pointer and memory.