Python_01_ variable _ comment _input_if_ indent

Source: Internet
Author: User

Personal notes, only as a study record, if there is a mistake.

Variable naming rules:

1: Variable name must be a combination of English letters, underscores, numbers
2: Variable name cannot start with a number
3: Variable name cannot be a keyword in python
4: Variable name cannot be Chinese
The variable name in 5:python is suggested to be underlined if there are multiple words (other languages commonly used hump method)
Constants cannot be defined in 6:python: All variables in Python are mutable, so the constant is represented by the variable name in all Capitals

Variable assignment:
name1 = "Laowang"
Name2 = name1
name1 = "Xiaozhang"
Does the value of the name2 at this time also change?
A, no, the value of name2 is still "Laowang", the value of name1 becomes "Xiaozhang"

Deletion of variables:
Age = 20
del age(delete variable reference, not free memory, memory recycle processed by GC)

Python code:
python2.x: Default encoding ASCII
python3.x: Default encoded Unicode

Comments in Python:

Python single line comment: Pound sign "#"
Python Multiline Comment: Three quotation marks beginning and ending "" "" "" "" ""
In fact, the three quotation marks of a multiline comment in Python are not real comments, but rather unreferenced strings!
Because it is not referenced, a string of three quotation marks is ignored by the Python interpreter, so it can be used as a notation

Input ():
Name = input ("Please enter your name:")
age = Int (input ("Please enter your Ages:"))
Input received by default is the str type (string)

If...else. Statement:
If name = = "Laowang":
Print ("Lao Wang")
Else
Print ("Xiaoming")
Note:There is no else in Python, but it is elif shorthand.

The indentation of Python:

The TAB key and the space can not be mixed, either with the tab indent or with a space indent (any space, as long as the indentation consistent line), the official recommended indentation is four spaces (the Text Editor tab key into 4 spaces)

Python_01_ variable _ comment _input_if_ indent

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.