Python_01 _ Variable _ comment _ input_if _ indent, python_01_input_if

Source: Internet
Author: User

Python_01 _ Variable _ comment _ input_if _ indent, python_01_input_if

Personal notes, only for learning records. please correct me if you have any mistakes

Variable naming rules:

1: The variable name must be a combination of letters, underscores, and numbers.
2: The variable name cannot start with a number.
3: variable names cannot be keywords in Python
4: The variable name cannot be Chinese
5. If the variable name in Python has multiple words, it is recommended to connect the variable names with underlines (Common camper in other languages)
6: constants cannot be defined in Python: all the variables in python are variable, so the variable names in full uppercase are used to represent constants.

Variable assignment:

1 name1 = "laowang"2 name2 = name13 name1 = "xiaozhang"

Does the name2 value change at this time?
A: No. The name2 value is still "laowang", and the name1 value is changed to "xiaozhang"

Deletion of variables:

1 age = 202 del age

Delete variable references, instead of releasing memory. GC processes memory reclaim.

Python encoding:
Python2.x: default encoding ASCII
Python3.x: Unicode by default

Annotations in Python:

Python single line comment: #
Python multi-line comment: the start and end of the three quotation marks are "" comment content "".
In fact, the three quotation marks for multi-line comments in python are not really comments, but strings that are not referenced!
Because it is not referenced, the strings caused by the three quotation marks are ignored by the python interpreter. Therefore, it can be used as a comment.

Input ():

1 name = input ("enter your name:") 2 age = int (input ("Enter your age :"))

The content received by input is of the str type (string) by default)

If... else... statement:

1 if name = "laowang": 2 print ("Old Wang") 3 else: 4 print ("James ")

Note: There is no else if syntax in python, but it is abbreviated as elif.

Python indent:

The tab key and space cannot be mixed, either tab indent or space indent (any space, as long as the indentation is consistent ), the recommended indentation is to use four spaces (the tab key in the text editor is converted to four spaces)

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.