The basic principles of computer day02

--- --- restore content begins

  - Computer Principle
         - five components of the computer
             - the CPU: + Control operation
             - Memory: temporarily storing, effective power, power loss of data.
            - Hard disk: permanent storage of data.
            - output devices: a display
             - input device: mouse, keyboard. . . 

    - What is the language of 
        communication between people of the media

     - what is the programming language? 
        Communication between human and computer media

     - Why programming? 
        By writing the code, so that the machine replace human work. 

    - Programming Languages category:
         - machine-language 
            binary: 01,010,101,101 
            language machine can directly read the 
            advantages: 
                high efficiency. 
            Disadvantages: low efficiency


         -Compiled language: 
            similar to the Xinhua Dictionary, the Oxford English Dictionary, the first compilation multiple use. 

        - interpreted language: 
            like simultaneous interpretation, while compiling it again explanation. 
                Explanation refers to the character to be able to understand the human machine can understand the 

        interpreter: 
            For example:. Python3 6.4 
            for machine translation to human language. 

        - happens when executing file py: (******* )
             1 . Executed interpreter, the interpreter is loaded into the memory
             2 . Py file will be loaded into memory
             3 run python code. 

        - variable (******* ) 
            amount may change. 
            Definition: 
                variable name = variable value 

            variable name: variable value equivalent of house number used to find the value of the variable. 
            = : Bind variable names for relations with the variable value. 
            Variable values: the data stored in memory. 

            note:
                Variables generated when the program is running in memory, the end of the program variables will be destroyed. 

        Data Type:
             - Integer: int 
                represents the identity ID, age ...

             - float: float 
                represents the height, salary ...

             - string: str 
                used to record home address ...

             - boolean type: BOOL 
                True or False 
                true and false judgment

             - dictionary: dict 
                in {} is defined, separated by a comma in parentheses can be stored a plurality of values, 
                each value is in a key: the value of storage form. 

                - is used to record the unique data 
                    key is unique 
                dict1 = { ' names ' : [ ' Lvlian Jie ' ,' Lu Silver Silver ' , ' 18 Tank ' ]}

             - set: set 
                to {} is defined, separated by a comma in parentheses can store multiple values. 
                Features: automatic de-duplication. 
                setl = {1,1,1,1,2}   # {. 1, 2}
 
            - List: list 
                of [] is defined, separated by a comma in parentheses can store a plurality of values 
                List1 = [. 1, 2,. 3, ' Tank ' ]

             - tuples: tuple 
                in () is defined, separated by a comma in parentheses can store multiple values 
                tuple1 = (1,2,3,4 ) 

            Note: 
                the internal data list can be modified, called the variable Types of. 
                Internal data tuple can not be modified, called hard type.


Today's Contents:
   - three characteristics of the variable 
        type: 
            viewing data type 
        id: 
            represents the variable address in memory, is a string of numbers 
        value: 
            the value of variables

   - comments 
        explain why the code is used. 
        Single-line comments: 
            # single line comment content 

        Multiline comments: 
            '' ' 
            footnotes multiple lines 
            ' ''
 
  - user interaction with the program 
        INPUT 
        Print
- formatted output % S: placeholder text string to replace - Basic operator - arithmetic operators - Comparison operators - logical operators - assignment operator -Chain assignment X = Y = 10 - Cross assignment X, Y = Y, X - decompression assignment X = (. 1, 2,. 3 ) X, Y, Z = () X, Y, Z = [. 1, 2, 3 ] - process control control process, control the occurrence of certain events. - if the branch judgment: Syntax: if judging criteria:
# condition if set up to perform Print ( ' condition is satisfied! ' )
# If the if condition is not satisfied, the execution here elif judging criteria: Print ( ' the other conditions are satisfied' )
# If the if condition is not satisfied, the executed here elif : determination conditions Print ( " Another condition is satisfied ')

# if if and elif conditions are not satisfied, the execution where the else :

# If the condition is not satisfied is executed Print ( ' condition is not satisfied ! ' ) Import Time List1 = [ ' Tank ' , ' Jason ' ] # Print ('18 year-old tank, really.') # of the type Print (of the type (List1)) # the above mentioned id Print (the above mentioned id (List1)) # 4648825800 # 4,620,657,608 the time.sleep ( . 5 ) Print ( " program end, is destroyed List1 ' ) # variable and non-variable # when data modification, id called constant variable type, otherwise called hard type. (Dictation) # variable List1 = [ ' Tank ' , ' Jason ' ] Print ( ' List1 before modification ID: ' , ID (List1)) list1.append ( ' power Long ' ) # [ 'Tank', 'Jason' ] .append (Long coke) Print (list1) Print ( ' after list1 modified ID: ', ID (List1)) # immutable: tuple tuple1 = (. 1, 2,. 3 ) Print (ID (tuple1)) Print (type (tuple1)) tuple1 = (2,. 3,. 4 ) Print (ID (tuple1) ) user interact with the program: iNPUT () input Print () output username = iNPUT ( ' input message: ' ) '' ' username = input (' enter username: ') Print (username) password = iNPUT (' please enter the password: ') Print (password) # if # username ==' Tank 'True # and: left and right sides of the conditions are True it is True, otherwise False # password ==' 123 'True # IF conditional: if conditional == True, the next execution of the code if IF username ==' Tank 'and password == '123': False and True --- # "False Print ( 'Login successful') the else: Print ( 'Login failed') # placeholders:% S str1 = 'handsome' Print ( 'Tank S%'% (str1,) ) # tank handsome str2 = 'faith with me, I'll be invincible!' Print ( 'self-confidence to develop mind 1:% S'% (str2,)) price1 the iNPUT = ( 'Please enter the user chargeback month month rent: ') All the iNPUT = (' Please enter the user's current balance: ') ! Print (' Dear mobile users, your monthly rent for the month [% s] yuan, account balance [% s] Element ' % (price1 , all)) basic operators: - arithmetic operators +: add -: Less *: multiplication /: retaining the decimal //: not divisible decimals %: In addition to the first and then take the remainder modulo. '' ' (. 1 +. 1) # 2 N1 =. 1 # N1 = N1 +. 1 # N1 + =. 1 # Print (N1) # 2 N1 + =. 1 # assignment operator: - = Print (10 -. 1) # . 9 # * = Print (12 is * 12 is) # 144 Print (. 11 /. 3) # 3.666 ... Print (//. 11. 3) # . 3 Print (. 11%. 3) # 2 # comparison operators Print (== 2. 1) # False Print (. 1> 2) # False Print (. 1 < 2) # True Print (. 1> = 2) # False Print (. 1 <= 2) # True # IS: comparing whether the two variables are equal id X = 10 Print (id (X) == id (X)) # True Print (X IS X) # True IF branch ' ' # # guess character game: guess whether the character entered by the user is 9527. # # = 9527 Number # # INPUT = GUESS ( 'Enter number to guess:') # # Print (GUESS) # Print (type (GUESS)) STR # # # # into the string type Integer # guess = int (gUESS) # Print (of the type (gUESS)) # int # # Print ( 'guessed it!') # # elif gUESS <Number the: # Print ( 'guess small') # # == Number The GUESS IF: # the else: # Print ( 'guess big!') '' ' The while loop: Grammar: the while judging criteria: # If the conditions are met the "cycle" the following code performs Print ( ' 111 ' ) BREAK : the end of the loop layer '' ' # Import Time # the while True: # Print (11111) # the time.sleep (. 1)

 

 

--- end --- restore content

Guess you like

Origin www.cnblogs.com/jiaolongchangjunyi/p/11580800.html