Python study notes on the third day

Python study notes on the third day

1. The continuation of yesterday learning content

2. Learn Today

  2.1 conditional: if and while

     2.1.1 if statement: This section has a certain basis, notes skipped content itself Baidu

     2.1.2 while statement: with 2.1.1

  2.2 cycle: for while

     2.2.1 for loop: for ... in ...

     2.2.2 while loop: as long as the conditions are met, the execution cycle (note infinite loop (never true formula)), conditions are not met then exit the loop

  2.3 range:

           Generating a random number sequence, including the beginning, not including the end

  2.4 dictionary dictionary

           Use key - value storage

           For example: query results by name, implemented list. Two list

      Create a "name - performance" dictionary dict

           Dictionary runs fast, but they consume memory.

           Note: The dictionary key must be immutable object, or an error occurs

       2.4.1 modify the dictionary

            Manipulate it directly, you have to find the key to modify the name, and then directly assigned to.

       2.4.2 Add

Default added to the end

       2.4.4 Find

             Note: Avoid key method does not exist:

                   1. judged by in

                   2. get method itself, if the key does not exist, returns None (not displayed by default in the interactive mode) or a specified value

      2.4.5 Delete

            2.4.5.1 Use pop method

                    pop(key)

  2.5 collection (set)

       set collection is not stored value 

       Repeated automatic filtering element in the set

               2.5.1 Adding elements

              add(key)

               2.5.2 remove elements

                                     

                                    

             2.5.3 intersection and union

                         2.5.3.1 intersection

                                   

                               

                         2.5.3.2 union

                    

                

                            2.5.3.3 intersection and union difference

          The difference is no corresponding value, but both are the same principles

   2.6 immutable (Development)

       2.6.1 str immutable objects

            

        

 

       2.6.2 list variable objects

 

 

 

  2.6 Functions

      A collection of methods can be called repeatedly: 2.6.1 definitions

      2.6.2 call:

            2.6.2.1 Built-in functions

                 2.6.2.1.1 abs () function is the absolute value

                 2.6.2.1.2 max () function is a maximum value, the maximum value of return

            2.6.2.2 Data Type Conversion: cast

            2.6.2.3 Note: The built-in functions can also rename, copy it to a variable. An error occurred while calling the function parameters, you must learn to see the error message.

            2.6.2.4 Custom Functions

                 2.6.2.4.1 Definition: The definition of a function  

                 2.6.2.4.2 expand: Python pep8 coding standard (Chinese version)

                 2.6.2.4.3 empty function: no function-defining a generally used pass. As shown below

                               

 

                 2.6.2.4.4 Note: The function can return multiple values, the result is essentially returns a tuple type. Defining a function name, and parameter (number determination) must function. If necessary, the data type of the parameter to be checked. Returns a return value, essentially returns a tuple type, if there is no return, automatically returns a null value None (return None)

Next week courses: string encoding, catch the exception

Guess you like

Origin www.cnblogs.com/tjlhappyboy/p/11209562.html