This time we learned to include tuples, dictionaries, and collections.
Tuple (tuple): Enclose with parentheses
If there is only one element, add a comma behind it --tup=
Tuples can be added
(1,2,3)+(4,5,6)--(1,2,3,4,5,6)
* indicates a few copies
Convert tuples:tuple1=tuple (list)
t= (' A ', ' B ', [' A ', ' B '])
t[2][0]= ' X '
t[2][1]= ' Y '
t= (' A ', ' B ', [' X ', ' Y '])
Tuples cannot be changed or deleted, but lists in tuples can be
Dictionary: Enclosed in curly braces
Key-value pairs:
D={key1:value1,key2:value2}
Increase:
By deleting:
Change:
Check:
Keys (): list of all keys
VALUES (): list of all values
Items (): key values are
-
Set collection
. Union for the set (123456) set1| Set2
. Intersection set1&set2
. Difference
. Symmetric_difference set1^set2
Set1 (1,2,3,4)
Set2 (3,4,5,6)
-
functions
Strings,tuples,numbers immutable ( immutable )
List, Set variable ( mutable "
keyword parameter ( **xx
default parameter: Default parameter must be placed on the last side
indeterminate length parameter ( *xx tuple
Variable scope
Global variables are scoped differently from local variables
Different life cycle
Global Variables declared with globals
6. anonymous function:lambda[arg1[,arg2,..... argn]]:expression
Sum=lambda a,b:a+b
Python section III