Python Learning (III.)--Variable and process control

Source: Internet
Author: User

One, variable

1. Variable naming rules:

Syntax: (underscore or letter) + (any number of letters, numbers, or underscores)

such as: a123,_a123,_a123_

The variable name must begin with an underscore or letter, followed by any number of letters, numbers, or underscores. Case-sensitive, that is: name is not the same variable as name. The same is forbidden for Python keywords and reserved words.

Python keyword:

Falseclass      finally     is         returnNoneContinue    for        Lambda     TryTruedef         fromNonlocal while and        del        Global      notWithaselif       if         or         yieldassert     Else       Import     Pass Break      except     inch         Raise

Note: In Python, variable names do not have types, but objects have; variable names are just references to objects (internally implemented as pointers)

2. Declaration and assignment of variables:

1)

Name = "123"#  1. Declare variable name#  2. Assign "123" to the variable name

2)

Name = "124= name #将name的值赋给变量name1
Second, user input
# !/usr/bin/env python # -*-coding:utf-8-*- # assigns the user input to the name variable name = Raw_input (" Enter user name:"# to print the input  Print name

Python3 has discarded the raw_input function, the difference between the Row_input function in Python2 and the input function:

Row_input: If the user input is a number, the user input is still obtained as a string, such as user input 123, the value of name is the string "123"

Input: If the user enters as a number, the user input is obtained in int type, such as user input 123, then the value of name is the number 123.

Third, Process Control

The program flow is divided into three kinds of structure: Sequential structure (code top-down execution), selection structure, loop structure.

1. Sequential structure

Number = 111"print" (number)print(name)

program run order as shown in the code, top-down, output results are 111, "12".

2. Select structure

Grammar:

1) If Condition:

    

Execute conditional code block statement If condition is true or continue execution of subsequent code

2) If condition:

Condition1

Else

Condition2

Execute the Condition2 code if the Condition1 code is executed if the condition is established

3) If condition 1:

Condition1

Elif Condition 2:

Condition2

Else

Condition3

If condition 1 is established, execute Condition1 code, otherwise run Condition2 code if condition 2 is set up, run Condition3 code if none of the above is true.

Python Learning (III.)--Variable and process control

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.