>>> print "Hello,world"
Hello,world
>>>
4
# A single-line comment "" " can be preceded by a semicolon, but will not have any effect unless there is more code on the same line, but this is not a common practice multiline Comment " "
Python
Advantages
- Python's positioning is "elegant", "clear", "simple", so the Python program looks always easy to understand, beginners learn python, not only easy to get started, but also in the future, you can write those very very complex programs.
- Development efficiency is very high, Python has a very powerful third-party library, basically you want to achieve any function through the computer, the Python official library has the corresponding modules to support, directly download the call, on the basis of the base library to develop, greatly reduce the development cycle, to avoid repeating the wheel.
- High-level language ———— when you write programs in the Python language, you don't have to consider the underlying details such as how to manage the memory used by your program
- Portability ———— because of its open source nature, Python has been ported on many platforms (modified to make it work on different platforms). If you are careful to avoid using system-dependent features, all your Python programs can run on almost any system platform on the market without modification
- Scalability ———— If you need a piece of your critical code to run faster or you want some algorithms to be private, you can write some of your programs in C or C + + and then use them in your Python program.
- Embeddable ———— You can embed python into your C + + program to provide scripting functionality to your program users.
Disadvantages:
- Slow, Python runs faster than the C language, and slower than Java, so this is the main reason why many so-called Daniel disdain to use Python, but in fact, this refers to the speed of slow in most cases the user is not directly aware of, Must rely on the use of testing tools to reflect, such as you use C a program to spend 0.01s, Python is 0.1s, so c directly than Python 10 times times faster, is very exaggerated, but you can not directly perceive through the naked eye, Because a normal person can perceive the smallest unit of time is 0.15-0.4s around, haha. In fact, in most cases python has been fully able to meet your requirements for the speed of the program, unless you want to write to the speed of the most demanding search engine, in this case, of course, it is recommended that you use C to achieve.
- Code can not be encrypted, because Python is an explanatory language, its source code is stored in the form of a name, but I do not think this is a disadvantage, if your project requires that the source codes must be encrypted, then you should not use Python in the beginning to implement.
- Threads do not take advantage of multi-CPU problems, which is one of the most common drawbacks of Python, the Gil, the Global Interpreter lock (interpreter lock), is a tool that the computer programming language interpreter uses to synchronize threads so that only one thread executes at any moment, The python thread is the native thread of the operating system. On Linux for Pthread, on Windows for win thread, the execution of threads is fully dispatched by the operating system. A Python interpreter process has a main thread and the execution thread for multiple user programs. Multi-threaded parallel execution is prohibited even on multicore CPU platforms due to the existence of the Gil. A compromise solution to this problem is discussed in more detail later in the Threads and Processes section.
Of course, Python also has some other small shortcomings, in this does not enumerate, I want to say that any language is not perfect, have good and not good at doing things, it is recommended that you do not take a language disadvantage to the advantage of another language to compare, language is just a tool, is a tool to realize the idea of the program designer, as we learned in high school geometry, sometimes need compasses, sometimes need to use the same setsquare, take the corresponding tools to do what it is best at the right choice. A lot of people asked me, which is the best shell and python? I replied that the shell is a scripting language, but Python is not just a scripting language, it can do more, and then someone who has a dead-point says there is absolutely no need to learn python, Python can do things that the shell can do, as long as you have enough cow B, And then the shell can write Tetris such a game, I can say to express only, not with SB theory, SB will pull you to the same height as he, and then with the full experience to knock you down.
Python single-line comments and multiline comments