The next day python Course summary
1. List
1) Definition: There may be a plurality of any type of value within [], separated by commas
2) the priority control operations:
by the index value to access (access + Reverse Forward Access): may be taken to keep
the slice (care regardless of the end, step)
longitudinal
members in operation and not in
additional
deleted
cycle
3).
# PS: Reverse step L = [1,2,3,4,5,6 ] # forward step l [0:. 3:. 1] # [. 1, 2,. 3] # Reverse step l [ 2 :: --1] # [3, 2, 1] # listing inverted L [:: --1] # [. 6,. 5,. 4, 3, 2, 1]
2. tuple
1) Definition: the ratio of list types, except [] replace ()
age = (11,22,33,44,55) essentially age = tuple ((11,22,33,44,55))
2) the priority control operation #:
# 1, according to the index value (Forward + Reverse take take): can only take
# 2, a slice (care regardless of the end, step)
# 3, a length of
# 4, operation members in and in not
# 5, circulation
3).
# Simple shopping cart, requirements are as follows: For more information Print product realization, the user enters the number of trade names and purchase, it will trade name, price, number of buy add to the list, if the input is empty or other illegal input require the user to re-enter msg_dic = { ' Apple ' : 10 , ' Tesla ' : 100000 , ' MAC ' : 3000 , ' Lenovo ' : 30000 , ' Chicken ' : 10 , }
3. Dictionary
1) Definition:. Key must be immutable type, value may be any type
= {info ' name ' : ' Kermit ' , ' Age ' : 18 is, ' Sex ' : ' MALE ' } # nature info = dict ({....}) or info = dict (name = ' Kermit ' , Age 18 is =, Sex = ' MALE ' ) or info = dict ([[ ' name ' , ' Kermit ' ], ( ' Age ' , 18 is )]) or {}.fromkeys(('name','age','sex'),None)
2) the priority control operation #:
# 1, the access key press value: can be kept desirable
# 2, the length len
#. 3, and members in operation in Not
#. 4, delete
# 5, key Keys (), the value of values ( ), key-value pairs items ()
# 6, circulation
4. collection
# Effect: de-duplication, relational operators, # define: knowledge recalled variable type is not the type of hash immutable type is a type of hash # define the set: set: may comprise a plurality of elements, divided by commas, elements of the set of three follow principle: 1 : each element must be immutable (the hash may, as key dictionary) 2 : no duplicate elements 3 : unordered object set is noted that different values will be stored together, a set of different used for calculating the relationship, without a single value in the collection entangled # priority control operation: # 1, the length len # 2, and the members in operation in Not # . 3, | collection # 4, & intersection # 5, - difference set # 6, symmetric difference ^ # 7, == # 8, superset:>,> = # 9, subsets: <, <=
# Following two sets, pythons python program, participants registration is the name of the collection, linuxs entry linux is the name of the program, participants set of Pythons The = { ' alex ' , ' Egon ' , ' yuanhao ' , ' wupeiqi ' , ' gangdan ' , ' biubiu ' } linuxs = { ' wupeiqi ' , ' Oldboy ' , ' gangdan ' } # obtains i.e. python registration and application program, participants linux set name Print (& Pythons thelinuxs) # find the name of a collection of all enrolled students Print (Pythons The | linuxs) # obtained only apply python program, participants name Print (Pythons The - linuxs) # obtained while participants did not name the two courses a collection Print (Pythons The ^ linuxs)
5. File Handling
File open () to write the file wt: write text read files rt: read file additional write file ut: additional write file during the execution of python file 1 . Start first python interpreter, loaded into memory 2 _ Load those python file. It is loaded into the interpreter 3. detection python syntax, the execution code
6. function portion
# 1, the syntax '' ' DEF function name (parameter 1, parameter 2, parameter 3, ...): ' '' document describes '' ' function body 1 function body 2 ... value returned by return ' ' 1. DEF (ie defind, translation is defined!): is the keyword to declare a function. 2 function name: used to call the function. Naming function should try to reflect the function of its representatives. Also it is to see its name knowing Italian! 3 (): function parameters in parentheses, parameters of the function may be one or more. 4. '' ' Notes ' '' / : write the recommendation to enhance the readability of the function! 5 function body: specific logic code. 6. The return : value returned by the function.
Three forms of defined functions
# 1, no reference: application scenario just perform some operations, such as interaction with the user, print
# 2, there are parameters: external parameters passed in accordance with need, and to perform the appropriate logic, such as statistical length, selecting the maximum value minimum value
# 3, empty function: design code structure
Three types of function calls
A statement form: foo ()
2 expression in the form:. 3 * len ( 'Hello')
. 3 which further a function of the parameters: range (len ( 'hello' ))