Personal Independent Blog Source:http://www.xbman.cn/Source:Http://www.xbman.cn/article/3Python is a kind of explanatory computer programming language. Using the indentation syntax, the feeling is a bit like a row version of the shell, it is important to note that Python to strictly control the indentation, the letter is case-sensitive, it is recommended to use 4 of the space to be programmed in the indentation. This makes the code look very layered. Don't mix tabs and spaces! Here's a look at some basics
注释
Suggest that we all develop a good habit of commenting code, one can look at their own code to quickly locate, and secondly give people to facilitate. Python annotations are available in a number of ways, often starting with #, and a multiline comment that ends with a three semicolon. Look at the following example:
# This is a comment print ' Hello word ' "Here is a multiline comment '
'
中文乱码?
The use of python2.7 shoes may encounter code written in Chinese after garbled can not perform the problem. Do this,
#!/usr/bin/env python#-*-coding:utf-8-*-Add the above two lines at the top of the file. The first line, tell the file Python interpreter location, is not a bit like the second line of the shell, solve garbled problem
The first Python program
#!/usr/bin/env pythonprint "Hello word!"
Write the above code into a file saved as .py
end of file, execute the following method
Python hello.py
Did you see the effect?
输入与输出
Output, Print command
Python2print ' Hello word ' python3print (' Hello word ')
Input, raw_input instruction
Python2name = Raw_input () Xxxpython3name = input () xxx
Variables and shell variables use a similar method, a=1,b= ' 123 ' in the CMD window directly invoke the variable just assigned to display the results
This article is from the "Magsun linux" blog, please be sure to keep this source http://weihaoxuan.blog.51cto.com/8698172/1924719
Python Dafa II-some basics (i)