For many developers, the Python scripting language should be heard. However, there are also various comments about the Python scripting language, what's more, the Python scripting language will disappear into the development family for a certain period of time.
I am not going to comment on others' right and wrong ideas here. I just want to talk about Python as a computer language from a more objective perspective. Python is an explanatory language and belongs to OpenSource projects. However, you can use it for commercial purposes.
It can also be sold on commercial product CDs. Of course, people can also get their installation programs or source code free of charge from www.Python.org or OpenSource. Python was originally compiled on an Apple computer, but now it can run on a mainstream operating platform in the world. It is not only for Windows.
In addition, Linux, Unix, and many other platforms can use it. In RedHat9, it is also installed as a required language for development. Python code types can be divided into three types: byte code and binary code optimization code.
Their suffixes are. py. pyc. pyo, which can be directly run. No compilation or connection is required. With these types of code, Python selects different types in different situations. As follows:
- [thread2.py]
-
- import thread
-
- import time
-
- input = None
-
- lock = thread.allocate_lock()
-
- def threadProc():
-
- while True:
-
- print 'sub thread id : ', thread.get_ident()
-
- print 'sub thread %d wait lock...' % thread.get_ident()
-
- lock.acquire()
-
- print 'sub thread %d get lock...' % thread.get_ident()
-
- print 'sub thread %d receive input : %s' % (thread.get_ident(), input)
-
- print 'sub thread %d release lock...' % thread.get_ident()
-
- lock.release()
-
- time.sleep(1)
-
- thread.start_new_thread(threadProc, ())
-
- print 'main thread id : ', thread.get_ident()
-
- while True:
-
- print 'main thread %d wait lock...' % thread.get_ident()
-
- lock.acquire()
-
- print 'main thread %d get lock...' % thread.get_ident()
-
- input = raw_input()
-
- print 'main thread %d release lock...' % thread.get_ident()
-
- lock.release()
-
- time.sleep(1)
At runtime, The Python script language detects. is there MyPython in the current directory of py. python file. If not, import MyPython. py and generate MyPython. pyc prepares for the next faster import. This reduces the initialization time. In addition, the Python script language automatically completes all this without user intervention. His syntax is relatively simple among many other languages, and he has ruled out a lot of tedious thinking. As follows:
- #! /Usr/bin/python
- A=2003
- Print
- A='Hello python'
- Print
- A= [2, 0, 0, 3]
- Print a [0]
-
- The above code can be run normally, and the result is as follows:
-
- 2003
- Hello python
- 2
For C ++, at least three sets of variables need to be declared. For the Python script language, a variable is enough. In addition, Python also has its own uniqueness in managing code blocks. The following is a comparison between Python and C ++ for the same While loop.