Lao Jia happy life day 04

variable

Variable name rules:

  1. Variable names consist of letters, numbers, underscores

  2. Variable names can not start with a number

  3. Variable names may have to be descriptive

  4. Variable names are case-sensitive

  5. Variable names prohibit the use of python keyword

  6. Variable names can not use Chinese and Pinyin

  7. Variable names Recommended wording:

    1. Hump ​​body
    2. Underline (the official recommended)

2. Constant

  1. Year-round constant amount
  2. Variable names in all caps, called Constant
  3. This python is not constant, as other language needs due.

3. Comment

  1. A single line (if the line) with annotation #
  2. Multi-line comments "" "Content" ""
  3. Three 'and' can
  4. The content of the comment will not be executed

4. The basic data types acquaintance

  1. String
  2. digital
  3. Boolean value
  4. List
  5. Originator
  6. dictionary
  7. set

String - str

  1. For storing some data strings
  2. In python as long as the string is enclosed in quotes
  3. "abs" 'skd'
  4. "" "Sdf" "" is the string assignment, the assignment is not a comment

Digital - int

  1. For calculating, for comparison
  2. In the first implementation of the contents of the assignment of the right of the equal sign
  3. python3: time division returns the decimal (floating point)
  4. python2: time division returns an integer (rounded down) regardless of an integer number, are integers.

a = "alex"

b = "dsb"

c = a + b # string concatenation

print(c)

a = "alex"+"dsb"*5

print(a)

String +: adding one character string

String *: Multiplying the string

Boolean value --- bool

For judging

True and false judgment

True - true

False - False

User interaction: (input / output)

INPUT () input -----

msg = input ( "precautionary statements")

Pring(msg)

Content input is acquired in a string python3

python2 the input data itself is acquired

type --- View data types

int () ----- casts string to integer

Flow control statements:

Single if

if ---- if

Indent results

if conditions:: statement has ended

Indent official recommended four spaces, or a tab space and tab can not be mixed.

if else a second election

if conditions:

Indent results

else:

Indent results

if elif elif elif a multi-select or deselect

elif - if at

if conditions:

结果

elif condition:

Result

elif condition:

结果

elif condition:

结果

if elif elif elif else a plurality Required

if if if if if a plurality of conditions selected from a plurality of

if conditions:

结果

if conditions:

结果

if conditions:

结果

if conditions:

结果

if nested:

if conditions:

if条件:

Result

== equal Analyzing

Guess you like

Origin www.cnblogs.com/lingege/p/11284847.html