Python Basics-Variables

Source: Internet
Author: User

Variable: You can change its state arbitrarily by assigning a value. Variables typically store changes or states in the execution of a program.

Format:

Variable name = variable Value

If you have a string type, you need to add the ' value '.

Example: Name= ' Xuzuo '

Age=18

The type of your value is automatically detected when you assign a value. You can also view the type of a value by type (variable name).

Example: Print (type (variable name))


Canonical definition of variable name:

1. Variable names can only be any combination of letters, numbers, or underscores

2. The first character of a variable name cannot be a number

3. Keywords cannot be declared as variable names (e.g. print break continue, etc.)

4. The assignment is best in English, close to the information you want to describe this value.


How to define:

Hump body Ageofxuzuo = Numberofstudents = 80

Underline (recommended) Age_of_xuzuo = Number_of_students = 80


Constants: There are constants in the variable, but there is no special format definition constants in Python. You can use all caps to represent constants.

(This method can be arbitrarily modified.) Just use uppercase to indicate "this is not easy to modify")


Comments:

With the depth of study, not long, you can write complex thousands or even tens of thousands of lines of code, some code you spent a long time to write, after some days to go back to see, it is too normal to read. In addition, you later in the work will find that a project is more than a few or even dozens of developers to do, you want to call someone else to write code, others will use yours, if the code is not annotated, you can not understand, let alone others, this production will be beaten. So in order to avoid this embarrassing thing to happen, be sure to increase the readability of your code.

Code comment split-line and multiline comments, single-line comments with #, multiline comments can be three pairs of double quotes "" "" ""


File header

#!/usr/bin/env python

#-*-Coding:utf-8-*-(with # coding:utf-8 no difference. )



Python Basics-Variables

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.