2019.10.18Python learning knowledge points summary

Program notes 04 and arithmetic operators

     1, the role comment

          To use their own familiar language, some code label instructions in a program to enhance readability.

     2, single-line comment (comment lines)

         Beginning with "#", "#" all the right things are as descriptive text, rather than a real program to be executed, only play an auxiliary role description.

         In order to ensure orderly, after the "#" add a space.

         Behind the single-line code increase Notes: (1) at the time of program development, can also use the "#" in the code behind (side) increases descriptive text.

                                                         (2) In order to ensure readability between, comments and code the code must be at least two spaces.

     3, multi-line comments (comment block)

         Many annotation information, a line can not be displayed, you can use multi-line comments.

         To use the multi-line comments in Python programs, it can be a pair of three successive marks (single and double quotes may be).

     4, arithmetic operators

          +, -, *, /, // (take divisible),% (taking the remainder), ** (power)

          In Python, "*" operator can also be used for string, the string is repeated calculation results of the specified number of results.

     5, arithmetic precedence

           After the first addition and subtraction multiplication and division

           Peer operator is calculated from left to right

           Priority may be used () calculated adjustment

 

05 Application execution principle

      1, the Big Three computer : the CPU, memory, hard disk.

      2, the principle of program execution

            Before the program is running, the program is stored in the hard disk.

            When you want to run a program: (1) operating system will first allow the CPU to copy the program into memory

                                                (2) The CPU executes the program code in memory

      3, Python program execution principle

           (1) operating system will first allow the CPU to copy the Python interpreter program into memory.

           (2) Python interpreter, according to the rules of grammar, from the CPU so that the code translation Python program down.

           (3) CPU is responsible for the implementation of the code translation done.

      Tip: Objective To establish a soft link, it is to respect the user does not remember what the interpreter uses a specific version.

       4 action, the program

             Procedure is used to process the data.

06 variables used and the type of

       1, variable definitions

             In Python, each variable must be assigned before use, after variable assignment, the variable will be created.

             Variable responsible for saving data.

             Equal sign (=) is used to assign values ​​to variables

             "=" Left is a variable name

             "=" Is the right value stored in the variable

        2, the type of the variable

              (1) no need to specify the type of the definition of variables in Python.

              (2) data types can be divided into non-numeric and numeric.

                       Digital type: plastic (int), floating point (float), Boolean (bool), a complex type

                       Non-numeric type: character, lists, tuples, dictionaries

                 Type function can be viewed using the type of a variable.

Calculate 07 variables of input and output

        1, between different types of variables calculated

             (1) can be directly calculated between the digital variable

             (2) using the "+" string concatenation string variable between

             (3) the string and integer variables can use the same "*" repeat string concatenation

             No other computing (4) numeric string variables and

         2, input variables

              The so-called input, is to get the user information by keyboard input with the code.

              In Python, if you want to obtain user input on the keyboard, the required input function

              About functions: a quasi-good function in advance, it can be used directly, without worrying about the internal details

              (1) input function keyboard input

                      a, can be used in Python function waits for user input from the keyboard input

                      b, anything Python user input are considered to be a string

                      c, syntax: string variable = input ( "message")

               (2) type conversion function

                       int (x) will be converted to an integer x

                       a float (x) to x is converted to a floating point

         3, formatted output variables

               You can use the print function in Python console output to

               If desired, while the output of character information, together with the output data, you need to use the format operator

               % Referred formatted operator, designed to handle the format string

                    a, a string containing%, referred to the formatted string

                    b,%, and in conjunction different characters, different types of data require different formatting characters

                         % S string

                         % D signed decimal integer

                         % F float

                         %% output%

                Syntax is as follows: print ( "format string" variable 1%)

                                           print ( "format string"% (variable 1, variable 2, ......))

08 variable naming

         1, identifiers, and keywords

              (1) Identifier

                       Identifier is a programmer-defined function name, variable name

                       Name needs to have "see-known name meaning" effect

                       a, identifier may consist of letters, numbers and underscores

                       b, can not start with a number

                       c, can not duplicate names and keywords

              (2) Keyword

                       a, a keyword that is already in use within Python identifiers

                       b, the keyword has a special function and meaning

                       c, does not allow developers to define and name the same key identifier

                Extension: import import a keyword "Kit"

         2, variable naming rules

              Python identifier is case sensitive

             (1) the definition of variables, in order to ensure that the code format, or so "=" should each retain a space

             (2) in Python, the variable name if required by two or more words, can be named as follows:

                      a, each word in lowercase letters

                      b, use "_ underscore" the connection between words

              Extension: Luo Feng nomenclature

Guess you like

Origin www.cnblogs.com/nuochengze/p/11701480.html