Summary of Python basics notes

Tuples Tuple

It’s an immutable list. The contents and total amount cannot be modified. Use parentheses

tup1=(‘zhansan’,1992,’physics’)

Allows new tuples to be generated using tuple operators

(5, 6) + (8,9,10) = (5,6,7,8.9, 10)

(‘good’,’bye’)*2=(‘good’,’bye’,’good’,’bye’)

t=’b’,’c’=(‘b’,’c’)

The fetch data is exactly the same as the list

If a tuple holds a list, the contents of the list can be modified

If a tuple has only one element, you must add a comma after the element to indicate that it is a tuple.

List: Content allows for extended storage of dynamically changing inefficient runtime data when needed to change trial weather, stocks, and other data

Tuple: the content is immutable, fixed and constant, the highest efficiency of preserving stable and constant data, such as country name and element period

Sequence of the Sequence

An ordered queue is a common name for a class of data structures: string, list, tuple, number sequence (Range).

The contents of a numeric sequence are immutable and are created using the range() function

R = the range of 0-99 (0100) r [set] = [three, four, five]

R2 =range(0,20,2) 2 is the step size

The fipolassi sequence 1,1,3,5,8,13…

Conversions between sequence types

List () is converted to a list

Tuple () converts to a tuple

The STR () function is used to join lists by converting single data to a string join

Print (“”.join(LST)) “” all elements in the list must be strings

A collection of

Python built-in data structure, no value dictionary.

Features: unordered, non-repeating elements, variable, allows mathematical operations, scattered storage

Create {} or set() function create

The set() built-in function converts from other data structures

Cl =set()

Intersection: Get the duplicate parts of two sets and create a new set

C3 =c1. Intersection (c2) c1. Intersection_update (c2) intersection_update(C2

Union: To combine two sets for deduplication

C3 =c1. Union (c2) No union update function

Difference set: The difference part of two sets

C3 =c1.difference(c2) Sets of one-way differences between C1 and C2

C6 =c1. Symmetric_difference (c2) Bidirectional difference set C1 in C2 and c2 in C1

c1.difference_update(c2) .symmetric_difference_update

Relational operations between collections

S1. Issubset (s2) Determines whether S1 is a subset of S2.

S1. issuperset(s2) Checks whether S1 is the parent set of S2.

S1. isdisjoint(s2) Determines whether duplicate elements exist in two sets. True does not exist, False does exist

Add, delete, and change collections

C1.add (” jurisprudence “) adds an element if it does not exist, if it does ignore it

C1. Update (list | tuple) add multiple elements at a time

C1. remove(“yuansu”) removes an element, no element error is reported

C1.discard (“yuansu”) ignores non-existent elements

Python’s built-in generators

Generative syntax [appended data loop statement loop or judgment statement]

List generator

LST =[I *10 for I in range(10,20)]

Lst2 =[I *10 for I in range(10,20) if I % 2= = 0]

Dictionary generation

dict1={i+1:list[i] for i in range(0,len(lst5))}

Set generator

Set1 ={I *j for I in range(1,4) for j in range(1,4) if I ==j}

More Python basics will continue to be compiled, and you can also comment!