Python Learning-1 days-basic operations

Source: Internet
Author: User

The python syntax is simple and clear, with a rich and powerful library. It is often nicknamed the glue language and is able to easily connect a variety of modules made in other languages, especially in C + +.

CurrentlyPython has become one of the most popular programming languages January 2011, it was tiobe   .

    now for Python3, programs that were designed in the early Python version do not work correctly on Python 3.0. to take care of the existing program, Python 2.6, as a transitional version, basically uses the syntax and library of Python 2.x, taking into account the migration to Python 3.0, allowing the use of some of the syntax and functions of Python 3.0. The new Python program recommends using the Python version 3.0 syntax. Most third-party libraries are now struggling to be compatible with Python version 3.0. Even if Python 3.0 is not immediately available, it is recommended that you write a program that is compatible with Python version 3.0 and then execute it using Python 2.6, Python 2.7来.


My first Python program

Create a hello.py (Python program with a py suffix)

#!/usr/bin/env pythonprint ("Hello Python")

The first line of the generic file specifies that #!/usr/bin/env python specifies how the script is used to perform

#!/usr/bin/python equivalent to writing dead python path;
#!/usr/bin/env Python will go to the environment settings to find the Python directory, recommend this writing


Comments and indents


General single-line comments using the # number

#这是一个注释

Multiline comments using three double quotes "or single quotes"

"This is the multiline comment the second line of the first line"


Python is indented as a block of code and does not need to use {} to indicate that the same indentation represents a block of code, and an error will be made if the number of indents is different. The following are indented in 4 spaces :

If True:print ("True") else:print ("Flase")


Simple assignment of a variable

Assigns a hello value to name and prints the name variable

#!/usr/bin/env pythonname= "Hello" print (name)

Assign a value to multiple variables at the same time, printing a,b,c three variable values.

#!/usr/bin/env pythona,b,c= "Wang", "Li", "Zhao" print (a) print (b) print (c)

There is also a way to print using the%s string format, as in the same way.

#!/usr/bin/env pythona,b,c= "Wang", "Li", "Zhao" msg= "" Print a,b,c the value of three variables is: The value of A is: The value of%s B is:%s C is the value:%s "% (A, b , c) print (msg)

Here, the%s represents the arguments on the back side, whereas the% (A,b,c) represents the variable value of a for the first%s, the second represents the variable value of B, and the third represents the variable value of C.






This article is from the "Carefree" blog, please be sure to keep this source http://birdcai.blog.51cto.com/11216068/1827911

Python Learning-1 days-basic operations

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.