Python Journey 2.0 (Python Foundation))

Source: Internet
Author: User

There are some basic rules for special characters in 1.python.

(1) #表示这后的字符为python注释.

(2) \ n Standard line delimiter.

(3) \ Continue on line. (that is, long statements can be broken down into lines using a backslash (\))

if (n==1) and (M== 2)    : print ("good")
------------------
Good

(4); Connect two statements to one line.

(5): Separate the head and body of the code. (Multiple statements form a block of Code (code group), a compound statement like If,while,def,class, the first line begins with a keyword, and ends with a colon:)

(6) statements (blocks of code) are expressed in the form of indentation.

Note: Indent 4 spaces to avoid using tabs.

(7) Python files are organized in the form of modules.

2. Assign values to variables.

(1) Assignment operator.

(=) is the primary assignment operator.

n=-m="Tom"

Note: In Python, objects are passed by reference, and when they are assigned a value, whether the object is newly created or already exists, the object's reference is assigned to the variable.

(2) Increment assignment.

The equals sign can be combined with an arithmetic operator to re-copy the result of the calculation to the variable on the left.

x=x+1---------- can now be written as x+ =1

+=,-=,*=,**=,%=,/=,&=, et

Note: Python does not support pre/post-increment/decrement operations such as X + + or--x.

(3) Multiple assignments.

>>>x=y=z=1>>>x1>>>y1>>>Z  1

(4) Multivariate assignment.

Another method of assigning multiple variables simultaneously is called multivariate assignment.

>>>x,y,z=1,2,'a string'>>>x1 >>>y2>>>z'a string'

2. The identifier.

The legal Python identifier string rules are similar to most other high-level languages written in C:

* The first character must be a character or an underscore.

* The remaining characters can be letters, numbers, underscores.

* Be sensitive to case.

3. Memory management.

(1) Variable definition.

A variable can be used only after it has been created and assigned, and once the variable is assigned, you will be able to access it through a variable command.

(2) Memory allocation.

The Python interpreter automatically assumes a complex task of memory management, which greatly simplifies the programming of the program. You just need to be concerned about the problem you're trying to solve, and it's good to have the underlying question given to Python to reveal it.

4. The first Python program.

We are already familiar with syntax, code style, variable assignment, and memory allocation, and now we can look at some slightly more complex code.

F=open ("test.log","w") f.write ("  This was my first line\n") f.write ("This ismy second line\n"  ) f.close ()
F=open ("test.log","a") #n=input ( " Pleae") f.write ("--------------") f.close ()

Python Journey 2.0 (Python Foundation))

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.