day1 python basis

A computer part: CPU, memory, external storage, input devices, output devices

 

Second, the installation and use of

1, the python interpreter installation

2, mounting editor python

3. Create a python file, print hello world!

 

Third, what is variable

Variables: the amount of change

Variable value: "tank", will produce a memory address in memory

Variable names: Pretty bound with a house number for the variable

=: Variable value used to bind to the variable

name = "tank"
print(name)

Naming variables

       Hump ​​nomenclature: AgeOfTank

       Underline name: age_of_tank #python strongly recommended

Variable names defined specification

1, to start with an English letter or an underscore named

        English alphabet begins with al #

        _al # start with an underscore

2, can not begin with a numeric name

      1a # error

3, the keyword can not be named

 'and','as','assert','break','class','continue','def','del','elif','else','except','exec','finally','for','from','global','if','import'

 

 Defined variable names a bad way

1, not to Chinese name

2, the variable name is too long

3, variable terms do not convey

 

Three features define the variables:

       id: The value of the variable used to represent only a memory address in memory

       type: type of variable values

       value: value of the variable

 

Third, the constant

constant:

It refers to the same amount

The constant nature is variable in python does not have any mechanism to limit that you can not modify a constant,

But python program to artificially limit yourself to meet all uppercase variables can not be modified to

Naming conventions:

    Variable names all uppercase

    SCHOOL = 'Hefei'

 

Fourth, the user interacts with the program

     Input:

            python3:      input()

            python2:

     Output: print ()

V. Notes

     Single-line comments: # shortcuts: ctrl + /

     Multi-line comments: triple quotes' '' '' 'shortcuts:' '' + Enter key "" "+ Enter key

 

Sixth, the basic data types

Digital Type:

   1, plastic: int

    2, floating point type: float

String Type: str

 

Priority control operation

1, according to an index value (forward + reverse take take): can only take

2, a slice (care regardless of the end, step)

3, the length len

4, members and not in operation in

5, remove the blank strip

6, slicing split

7, circulation

 

Seven formatted output

Dear customer, hello! Your month deducted 99 yuan bill, left 0 yuan

# By some placeholder character for a location in the replacement string

Placeholder:

      % S: can replace any type

      % D: can be replaced by a digital type

Example;

  Dear customer, hello! Your phone bill this month deducted yuan% s,% d remaining yuan

 

 

operation

name =  ' a1eX'

1, both sides of the removed name spaces corresponding to the variable value, and outputs the processing result

name = ' a1eX'
print(name.strip())

 

2, it is determined whether the variable name value that corresponds to 'a1' at the beginning, and outputs the result

name = ' a1eX'
print(name.startswith('a1'))

 

3, it is determined whether the value corresponding to the variable name to 'X' at the end, and outputs the result

name = ' a1eX'
print(name.endswith('X'))

 

4, the value of the variable name corresponding to the '1' is replaced with 'P', and outputs the result

name = ' a1eX'
name1 = name.replace('1', 'p')
print(name1)

 

5, the variable name according to the corresponding value '1' is divided, and outputs the result

name = ' a1eX'
print(name.split('1'))

 

6, the corresponding value becomes the variable name in uppercase, and outputs the result

name = ' a1eX'
print(name.upper())

 

7, the name variable value corresponding to lower case, and the output

name = ' a1eX'
print(name.lower())

 

8, please outputs of the two character values ​​corresponding to the variable name?

name = ' a1eX'
print(name[1])

 

9, please output the first three characters of the name value of the corresponding variable?

name = ' a1eX'
print(name[0:3])

 

10, please output the value of two variables corresponding character name?

name = ' a1eX'
print(name[-2:])

 

11, output a value corresponding to the variable name index position 'e' where?

name = ' a1eX'
print(name.index('e'))

 

12, to obtain sequences, removing the last character. The; Oldboy is acquired oldbo.

name = ' a1eX'
print(name[:-1])

 

Guess you like

Origin www.cnblogs.com/xhr8382/p/11080069.html