Re-learn python learning the third day

continue Statement

effect:

     For loop (while,

for), the statement is not executed after the cont inue within this cycle, start a new cycle times.            

Description:

The true value of the expression at 1, continue to perform statement in the while statement, while statement will jump directly to the restart JUDGE cycling conditions

After 2 ,. continue statement executed in the for statement, will remove a variable from the binding data object may be circulated again iteration

 

List

   definition:

       List is a container

       List is a sequence of the container can be changed

       The list is a series of elements, there may be no relationship between the elements and the elements, but the order of their relationship.

   Create a list:

       L= []

   Constructors list

       list()

       list(iterable)

note:

   In Python3 in range () function returns an iterable (type of object), rather than the type of list, it will not print when printed list

   Python3 in the list () function iterator object, the range can be returned iterator objects () into a list,

Variable type is returned as a list

   But the range in Python2 () function returns a list of

1. Arithmetic Operators

       +

+=  *  *=

       1 + Plus for splicing listing

       + = 2 for a list of the original right iterables stitching, binding list for

           List = list +

       3.*

Generate repeat list

       4. * = Repeat list generated assignment list of the original

   2. Comparison Operators

       Operator: <<=

>  >= == !=

       Explanation

           Compare the list of rules with the same string comparison rules

           Each list requires two elements can be compared in order, otherwise the type of error occurs

   List of index operations

       1. index value

           grammar:

               x = list [Expression whole book]

           usage:

               It is equivalent to the index of the string (the same index into forward and reverse index

       2, the index assignment

           List is a variable sequence elements in the list can be changed by assigning index

           grammar:

           List [integer-expression] = expression

       3. slicing list

           1 slice value

               List [starting index: Index termination: step]

               Slice the value of the list element is removed from the original list of wanted to form a new list again

           2, * slice assignment

           effect:

               Change the arrangement of the original list, and modifications can insert data syntax:

               List [slice] = iterables

           Description:

               Right slice assignment assignment operator (=) must be "optional objects substituting

           Precautions:

               For the step size is not equal to 1 slice assignment on behalf of the number of selectable objects on the right side of the assignment operator elements provided, it is equal to a given number of slices cut out segments

       List comprehensions inlay

           grammar;

               [Expression for variable 1]

           [+ = Operator list for a variable in iterables 1 if true value of the expression 1

               for variable 2 in iterables 2 if the true value of the expression 2]

           List comprehensions

               List comprehensions create a list of expressions with iterables

           effect:

               Create a list syntax:

               [Expression for variable in iterable]

               [Expression for variable in iterable if the true value of the expression]

       del statement

           Elements can be used to delete the list

           grammar:

               del list [integer-expression]

               del list [slice]

       Exercise:

           Already have a list:

               L= [3,5]

           With indexing and slicing operation, changes to the original list:

               L =[1,2,3,4,5, 6]

           The list of reverse results are as follows:

               L =[6,5,4,3,2, 1]

           Then delete the last element results are as follows:

               L =[6,5,4,3,2]

           python3 common series function

           lex (x) returns the length of the sequence

           max (x) returns the maximum value of the sequence

           min (x) returns the minimum value of the sequence

           Return sequence of all elements sum (x) and

           any (x) true value of the test, if there is a true value is returned in the list select True

           

     Exercise:

           Write program that allows the user to enter a number of positive integers, a negative input end of the input when the user input digital storage in the list

1. Print a list of numbers there

2. The average value of the numbers

3. To find the maximum number of this number

Such as:

   Enter: 1

   Enter: 2

   Enter: 99

   Enter: 100

   Enter: -1

   Printing is as follows:

       List is: [1,3,99,100]

       The mean is: 50.5

       The maximum value is: 100

A list of commonly used methods:

1. List.append (obj) add new objects in the end of the list

Parameters: obj - added to the end of the list

Return value: no return value, modified the original list

2. list.exten (seq) a plurality of additional one-time value of the other sequences in the end of the list (list with a new extension to the original list)

       Parameters: seq - a list of elements

       Return value: no return value, but will add a new list of contents in the list that already exists

3. list.ount (obj) statistics for the number of times an element that appears in the list

Parameters: obj - the object list of statistics

Return Value: Returns the number of elements that appear in the list

Index position 4. lise.index (obj) a first value to find a match from the list

5. list.inset (index, obj) into the list object

Parameters: index - the index of the object obj need to insert position

             Obj - to insert the object list Returns:

       This method does not return a value, but specifies the location to insert the object list

6. list. Pop (index = 1) the removal of one element of the list (the default last element), and returns the value of that element

Parameters: obj - optional parameter list element to remove the element index values, can not exceed the total length of the list, the default is index = -1

       Removes the last element of the return value:

       This method returns the list of elements to remove heavy objects    

7. list. The first match remove (ob5) remove a value in the list of

       parameter:

           Obj - the list object to remove Returns:

           This method does not return the value of the first occurrence but will remove a value in the list of

 

8. list. reverse()

       Parameters: Nall

           Reverse elements in the list

       return value:

           This method does not return a value, but will reverse the sort order of the list elements

9. list. Sort (cmp = None, reverse = False) to sort the list of the original

       parameter:

           Cmp - optional parameter, if this parameter is to use the method of this parameter specifies the sort

           reverse collation, Ireverse = True descending order, reverse

False Ascending

       return value:

           This method does not return a value, but a list of objects arranged team

Exercises list of operations

   Write the name of a management system:

       Functional requirements:

1. Add a new name

2. Delete a name

3. Modify a name

4. Query a name

5. Exit the System

List and string comparisons:

Have sequential relationship between the list 1 and the strings are sequence elements

2. The strings are immutable sequence, the sequence list is variable

3. Each element can only store strings of characters, and the list can store any type of element

4. List and strings are iterables

 

Tuple

1. Definitions:

Tuples are immutable sequence, like a list of tuples that can store data of any type of container

2. tuple representation

With parentheses () enclosed, individual elements enclosed in the comma (,) to identify individual objects or tuple

3. Create a literal empty tuples

t = () # Create an empty tuple t with bindings

4. Create a literal non-empty tuples

Example:

    tl=()

              print(type(t1))

           t2 = 200,

              print (type(t2))

            t3 (20)

            print(type(t3)

            t5 = 100,

200, 300

            print

(type(t5))

            # Error case

           t4 = (20) bound an integer of 20, instead of a tuple

            print

(type(t4))

            x,y,z-(100,

200, 300) sequence assignment #

            print

(type(x), type(y), type(z))

 

Constructor tuple 5. tuple

      tuple()

Generating an empty array equivalent to ()

      tuple(iterable)

It generates a new tuple with iterables

6. The operational tuples, comparison operation, sections identical index a list, and

Note:

       Tuple does not support indexing the assignment and slice assignments

Guess you like

Origin www.cnblogs.com/linxingh/p/11078696.html