day 01 python basis

 Essay:

A programming language

   1. What is the programming language?

    Expression can be recognized by a computer programming language mentioned above, i.e., language communication medium, and a computer programming language to communicate with a programmer medium. In the programming world, a computer is more like a slave to the purpose of human programmed to command the slaves to work.

  2. What is programming?

        Programming that is based on the needs of programmers to write down their thoughts flow in accordance with the syntax of a programming language style, the result is the output file that contains a bunch of characters.

    Emphasize:

        Before the program is not running with the ordinary file is no different, only at run time, the characters written in the document have specific grammatical meaning.

 

The second computer part

    CPU

    RAM

    External memory

    input device

    Output Device

 

Installation and use of three of python

    1. Install the python interpreter

    2. Install pycharm Editor

    3. Write python code and output print hello world!

print('hello world')

Four Variable

    Variables: the amount may change.

  1. Variable values: a real memory address stored in the memory, 'tank', is generated in memory - the memory address parts. .

  2. Variable name: value for the variable binding relationship, the equivalent of a house number, used to bind variables.

  3 =: variable value used to bind to the variable.

  4. Assignment = No: Binding the value of the variable to the variable name.  

name = 'apple'
print(name)

 

  The variable naming convention:

      Hump ​​nomenclature: AgeofTank

      Note: python is strongly recommended to use an underscore name: age_ of_ tank

  6. The variable names defined specifications:

          To begin with a letter or an underscore English name (name can not start with a number 1a and error !!!)

                     For example: a letters beginning ab, start with an underscore _ab;  

          Keywords can not be named:

                         例如:  'and', 'as',’assert', 'break', ’ class',’ continue','def’, 'de1',’elif', 'else',

                            'except', 'exec' ,’finally', 'for','from','global', 'if', 'import',in',’ is',

                            'lambda', 'not', 'or’,'pass','print',’raise', ’return',’try', while', 'with','yield'

  7. Define the variable names a bad way:

                   a. Do not Chinese name

                    b. the variable name is too long

                    c. variable terms do not convey

  8. The  definition of a variable three characteristics:

               id: value of the variable used to represent the only parts of a memory address in memory.
               Note: Logically speaking, then id variable values, the memory address is not the same. However, in a certain length of id, it sets the value of the same variable Python unified stored in the same memory address, the following code as their location;
            
name = 'apple'
name2= 'apple '
print(id(name))
print(id(name2))
              type: the type determination of the value of the variable
 name1 ='hello'
 print(type(name1))
             value: value of the variable 

           

name2= 'hello'
print(name1==name2)

 

Five constants

    Not change amount.

    Named to all uppercase.

    Not can not modify them, but everyone who ordained all uppercase variables are called constants, can not be modified.

 

= SCHOOL ' College '

 

Six user to interact with the program

    Input (any type of data input and output of the input string are):

        input()

    Output:

        print()

= the INPUT name ( ' Please enter the name: ' )
 Print (name)

Seven formatted output

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

 

    # 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.

 

Eight basic data types

    1. Digital Type:

        Integer: int

 

        Float: float

 

    2. String type

        Role: name, sex, nationality, address and other descriptive information

 

        Definition: single quotation marks \ double quotes \ three marks, a string of characters

            name='tank'

 

        Master priority actions:

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

          

# Forward taken: 
str1 = ' Hello World ' 
Print (STR [0])     # H 
Print (STR [. 9])     # R & lt 
# Reverse taken: 
Print (str1 [-2])    # L

 

 

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

# 5-1 length 
str1 = ' Hello World ' 
Print (STR [0:. 5])   # Hell 

# step 
Print (STR [0: 12 is: 2])    # hl0wrd

 

            3, the length len

print (referred to as (str1))

 

            4, members and not in operation in

print('h' in str1)    #True

 

            5, remove the blank strip

# Shift left: 
str1 = '    Hello     ' 
Print (str1.strip ()) 

# remove the specified character 
str2 = '     Hello!! ' 
Print (str2.strip ( ' ! ' ))

 

            6, slicing split

str1='hello  world '
print(str1.split(''))    #['hello','world']

 

            7, circulation

 

for line in str1:
print(line)

 

        You need to know:

            1, strip, lstrip (removed the left margin), rstrip (remove blank on the right), it is the same usage

            2, lower (all lowercase inflicted), upper (both ended up capital)

            3, startswith (determined character is equal to the value at the beginning of the input), endswith (end determines whether or equal)

            4, format three games are played

                      The position of formatted

                      According to the index format

                      By name format

            5, split (slice), rsplit

            6, join (string concatenation, string concatenation only)

            7, replace (string replacement)

            8, isdigit (numeric string is determined)

 

= str1 '     Hello World     ' 
# . 1, 
Print (str1.strip ())
 Print (str1.rstrip ())   # right of 
Print (str1.lstrip ())    # left 
# 2, 
Print (str1.lower ())    # lowercase 
Print (str1.upper ())   # D = uppercase 
# . 3, 
Print (str1.startswith ' Hello ' ))    # True 
Print (str1.endswith ( ' LD ' ))        # True 
# . 4, 
#4.1 
Print ( ' name {}, Age {} ' .format ( ' Apple ' , 12 is ))
 # 4.2 
Print ( ' name {0}, Age {}. 1 ' .format ( ' Apple ' , 12 is ))
 # 4.3 
Print ( ' name {name}, Age Age {} ' .format (Age = 12 is, name = ' Apple ' ))   # sequence can easily 
# . 5 
Print (str1.split ( '' ))
 # . 6 
Print ( '   '.join(['apple','12','from anhui']))
#7
str2=str1.replace('hello','people')
print(str2)
#8 
choice=input('功能[0][1][2]:')
print(choice.isdigit())

 

 Nine comments

Single-line comments: #
shortcuts: ctrl + /


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

    " '" + Enter key

 

 

Classwork:

= name ' Alex ' 
# . 1) removed on both sides of the value corresponding to the variable name spaces, and outputs the processing result 
Print (name.strip ()) 

# 2) determines whether the value corresponding to the variable name beginning with "al", and outputs the result Print (name.startswith ( ' Al ' ))
 # . 3) determines whether the value of the corresponding variable name ending in "X", and outputs the result Print (name.endswith ( ' X- ' )) 

# . 4) to a value corresponding to the variable name the "l" is replaced with "p", and outputs the result 
NAME2 = name.replace ( ' L ' , ' P ' )
 Print (NAME2) 

# . 5) the variable name corresponding to segmentation according to "l", and outputs the result . 
Print (name.L ' )) 

# . 6) corresponding to the name of the variable value becomes capital, and outputs the result Print (name.upper ()) 

# . 7) corresponding to the name of the variable value becomes lower case, and outputs the result Print (name.lower ()) 

# ? 8) make the output value of the name variable corresponding to the second character 
Print (name [2 ]) 

# . 9) Please outputs the first three characters values name corresponding variable? 
Print (name [0:. 4 ]) 

# 10 ) Please outputs two character value corresponding to the variable name? 
Print (name [-3: -1 ])
 Print (name [-1 ]) 

# . 11) requested output value corresponding to the variable name index where "e" position ? 
NAME2 = name.strip ( ' the X- ' )
 Print (len (NAME2))
 #12) acquisition sequences, removing the last character. Such as: oldboy then get oldbo. 
Print (name.strip ( ' X- ' ))

result:

 

 

Guess you like

Origin www.cnblogs.com/xhpxhp/p/11078561.html