Python is a high-level programming language used to write programs, and its scope of application is as follows:
- Write website, background service and other website applications;
- Write small tools for daily needs, including script tasks, etc.;
- Package the programs developed in other languages for easy application.
Python has a large number of basic libraries and is easy to write. The disadvantages are:
- Slow running
- Cannot be encrypted
Python file operation
Python has two environments for running code in command line mode and interactive mode.
In the interactive mode (in the command line mode, enter python and press Enter to jump to this mode): directly enter the code and press Enter;
in the command line mode: the python file ends with .py, use the command python when running <file name>.py can run. Under Linux, you can run the py file directly to execute the file, as follows:
- Add this statement to the first line of the .py file:
#!/usr/bin/env python
- Execute commands to increase permissions:
chmod a+x <文件名>.py
- Enter at this time
./<文件名>.py
to run
python input and output
Output
Use print
function to output, the basic format is as follows:
- The output content is a string:,
print '字符串'
where the string can be caused by "or" ( cannot be mixed ) - The output content is a number:,
print 数字或表达式
for exampleprint 100
Note: This function can be followed by multiple strings, separated by commas to form a string of output. When a comma is encountered, it will be converted into a space. For example: print 'There is','an','apple'
the output result isThere is an apple
enter
Use raw_input
functions for input, the basic format is as follows:
* name = raw_input('提示信息:')
* [Name is a variable name, the prompt information in () is optional]
At this time, the screen will let you input characters, and press Enter to assign the name successfully. In interactive mode, either input variable name or use print
function output. as follows:
>>> name = raw_input()
liming
>>> name
'liming '
>>> print name
liming
>>>
raw_input
The return result of the function is always a string>>> s = raw_input() 12 >>> s '12' #输出为字符串