I. Explanatory language
python is an interpreted language, which means:
l after writing the code can run without compiling the connection, save debugging time
l python interpreter is very well implemented in most systems, so the code you write can run on any system
But it also means:
l interpretation of the efficiency of the implementation is relatively low, so the program is also less efficient operation, intuitive is the long running time
ii. fields of application
Although there are shortcomings, but python It 's definitely a good programming language. Any language has its own applicable fields and scenarios,python 's application areas are mainly the following:
l develop small tools for your daily needs, including the scripting tasks required by your system administrator, and more.
l web programming, such as web development and back-office services. python Efficient features make it particularly suitable for the agile development of the site, enabling fast and iterative functionality. And in the web The field has a lot of frameworks to choose from, such as flask django
l as an adhesive for other languages. A common scenario is to first use python to develop a system prototype, a performance critical section, or a section with special requirements , and then rewrite it with C + + by python called.
Third, installationVersion Status
l PythonThe program you are writing needs an interpreter to run, so downloadpythonis essentially downloading apythoninterpreter. Becausepythonthe popularity of the interpreter version is also more than one, usually the version used isCPython, which is usedClanguage-written interpreter, from the official website (https://www.python.org/)the download isCPythoninterpreter. ForWindowssystem, directly download the installation, installation method is a fool-type installation.
l python There are currently two versions, that is, 2.x 3.x There are quite a few differences between the two, and all messages show 2.x 3.x python3.x version.
l after the installation is successful, in the Open Command Console window, enter python , or in the Start menu ( Windows installation) found under python Open, you can enter python Interactive mode:
* Here's >>> That means you've entered the interactive mode.
* input exit () and enter to exit interactive mode
So what's the use of this interactive mode? Interactive mode provides the ability to let you write code that immediately displays results, which is useful for learning and debugging programs.
Iv. Basic1.Print Output StatementsPrint
Enter in interactive mode:
P rint (' Hello World ')
? Note that there is no semicolon at the end, and No semicolon at the end of the Python statement
? both single and double quotation marks in Python represent strings
Enter to see the results printed out
2.Get user Inputinput
Python3 No Raw_input the
for input function, all input will be treated as a string:
3.numbers and Expressionsü subtraction to take the remainder inpythonthe same applies to
Note: Division in python There are two kinds of forms, namely / and the // , for 1 divided by 2 To say:
the results faithfully According to the results we expected, and 1//2 The result is 0 , this is because // A division that represents integers, and the result remains an integer, which ignores the decimal place.
ü exponentiation Operation**
** On behalf of the exponentiation, 2** 3 The result is 8 , while - 3**2 The result is -9 , note that the precedence of the exponentiation is greater than the minus sign, so if you want to ask -3 Square, the parentheses are required:
ü Python3 free to handle long integers without adding L theü Hex and octal
hexadecimal number to 0x Start
octal number to 0o Start
4.Common Functionsü exponentiation functionPOW
2**3 with the Pow (2, 3) is the same
ü Absolute Value functionABSü Roundinground5.Moduleü How to use:
1. Direct Import Import Math
>>> Import math>>> Math.floor (32.9) 32
2. Simple Import From Math Import sqrt
>>> from math import sqrt>>> sqrt (9) 3.0
ü CmathModule
Math module cannot handle imaginary numbers
Cmath can handle imaginary numbers:
>>> Import cmath>>> cmath.sqrt ( -1) 1j
ü Use__future__module provides support for new features6.Save and executeü throughIDLEWriting code
Windows version of python has built-in IDLE , with this tool, there is basically no need for other IDE the
ü run from the command promptpythonScriptü let the script run like a normal program
in the Unix Add the following header line:
#!/usr/bin/env python
Let the script have properties that can be executed:
$ chmod a+x hello.py
Simply enter the file name to run
$ hello.py
Windows under as long as python install correctly to double-tap open
Note: The program will flash through, so you need to add a line at the end of the program :
Input (' Press <enter> ')
7. Notes #8.stringü single quotation marks mixed with double quotesü Escape Character \ü Stitching Strings
Two adjacent strings will be interpreted as a string
Plus stitch String
ü Convert to String
str () and the repr ()
ü Long String
Use " " to wrap a newline string
single quotation marks can also be wrapped, at the end of the add \ that is, escape wrapping, and this method also applies to expressions and statements.
ü Raw StringR"'ü Unicodestringu"'
Python3 Default Support Unicode
Python Learning notes 01--Basics