Python Dafa II-some basics (i)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.