Python BASICS (3) and python Basics
My life is short. I want to learn Pyhton.
Python is an object-oriented, interpreted computer programming language, invented by Guido van rosum at the end of 1989, the first Public release was released on July 15, 1991. The Python source code also complies with the GPL (GNU General Public License) protocol. The Python syntax is concise and clear, and has rich and powerful class libraries. It is often called the glue language, and can easily connect various modules (especially C/C ++) made in other languages. A common application scenario is to use Python to quickly generate a prototype of a program (sometimes even the final interface of the Program) and then have a special requirement on it, rewrite with a more appropriate language. For example, if the graphic rendering module in 3D games has high performance requirements, you can rewrite it with C/C ++ and encapsulate it as an extension class library that can be called by Python. Note that you may need to consider Platform issues when using the extended class library, and some may not provide cross-platform implementation.
The formal installation and operation steps of Python are described in section 2nd of Python, and the next step is to enter the world of code !!!
Windows has installed the default Interactive Programming client when installing Python. The Prompt Window is as follows:
In Python, you can remember the general computing results of the computer language and the simple output language. For example, input the 'hello world' content in the python prompt and press the Eter to see the results!
Script-based programming
Call the interpreter through the script parameters to start executing the script until the script execution is complete. After the script is executed, the interpreter is no longer valid.
Let's write a simple Python script program. All Python files use the. py extension. Copy the following source code to the te. py file.
Print "Hello World ";
Save as the te. py file. HereRequiredSetEnvironment Variable of PATH
The output result is:
Python identifier
In python, identifiers consist of letters, numbers, and underscores.
In python, all identifiers can contain English letters, numbers, and underscores (_), but cannot start with a number.
The identifiers in python are case sensitive.
The identifier starting with the following line is of special significance. A class attribute that starts with a single underscore (_ foo) represents a class attribute that cannot be accessed directly. The class must be accessed through the interface provided by the class, and cannot be imported using "from xxx import;
(_ Foo) starting with a double underline represents a private member of the class; (_ foo _) Starting with and ending with a double underline represents a special identifier for special methods in python, for example, _ init _ () indicates the constructor of the class.
Python reserved characters
The following list shows reserved words in Python. These reserved words cannot be used as constants, variables, or any other identifier names.
All Python keywords only contain lowercase letters.
And |
Exec |
Not |
Assert |
Finally |
Or |
Break |
For |
Pass |
Class |
From |
Print |
Continue |
Global |
Raise |
Def |
If |
Return |
Del |
Import |
Try |
Elif |
In |
While |
Else |
Is |
With |
Except |
Lambda |
Yield |
Line and indent
The line and indentation in Python are very strict. The biggest difference between learning Python and other languages is that the Python code block does not use braces ({}) to control classes, functions, and other logic judgments. Python uses indentation to write modules.
The number of white spaces for indentation is variable, but all code block statements must contain the same number of white spaces for indentation.
When writing code, you may accidentally add a space or Tab:
So we will pop up when this error occurs.
This error indicates that the code you wrote has a format error, so we can see that there is a small space before the if, it is hard to see when writing code. It is a stage with few codes. If you don't pay attention to it when giving you hundreds of rows, it will make you unable to proceed.
So we should always pay attention toLine and indent.
Python quotation marks
In a small example, we can see the function of quotation marks!
Single quotation marks ('') and double quotation marks ("")
Three quotation marks ("""""")
Python annotations
Python requires a lot of comments, so that you can easily find the place you want to insert when you write a project and insert a function method. What symbol is used for comments? That's the # symbol!
The comments in your project code will not appear in the results!
Python waiting for user input
Wait for the user's input function raw_input in Python
(Today we are talking about Python's first knowledge of the editor. Do you feel that the Python compiler you see has a small amount of code! And it is like a bandit. Other famous languages can also call libraries. 1)