Parisgabriel:python Full Stack engineer (0 basics to Mastery) Tutorial 13th

Source: Internet
Author: User
Tags arithmetic arithmetic operators iterable naming convention set set shallow copy

ParisgabrielThank you for your support your reading evaluation is my best motivation I will insist on the layout of the content and the occasional mistakes do better



                  Stick to a daily subscription every day. Grey often thanks for being a dead powder also wide to

python ai from beginner to proficient

Set Set:
The collection is a mutable container
Data objects within a collection are unique (cannot be duplicated)
A collection is an unordered storage structure. The data in the collection has no sequencing relationship
The elements within the collection must be immutable objects
Collection is an iterative object
A collection is equivalent to a key without a dictionary (the key is a collection of data)
(equivalent to a combination of dictionaries and lists)

To create a collection:
s = set () #空集合
s = {3.14,true, (1970.1.1), "Hello"} #非空

Constructor for the collection:
Set () Creates an empty collection (cannot use {} Otherwise it is a dictionary)
Set (iterable) creates a new collection with an iterative object
Create new collection content repetition will automatically go back

For example:

Operation of the collection:
Intersection, set, complement, subset, superset
& Generate the intersection of a set of even collections:
Repeating part
S1 ={1,2,3}
S1 ={2,3,4}
S3 = S1&s2 #s3 = {2,3}
| Generate a set of two collections:
All non-repeating sections
S1 ={1,2,3}
S1 ={2,3,4}
S3 = S1 | S2 #s3 = {1,2,3,4}
-Generate a complement of two sets:
Equivalent to subtraction
S1 ={1,2,3}
S1 ={2,3,4}
S3 = S1-s2 #s3 = {1}
^ generates a symmetric complement of two sets:
equals subtraction Addition
S1 ={1,2,3}
S1 ={2,3,4}
S3 = S1 ^ S2 # (S1-s2 | s2-s1) #{1, 4}
> determines that a collection is a superset of another collection
< determines that a collection is a subset of another collection
S1 ={1,2,3}
S2 ={2,3}
S1 > S2 #true S1 is a superset of S2
S1 < S2 #true S1 as a subset of S2
(including relationship judgment)
= =! = Set same/different:
S1 ={1,2,3}
S2 ={3,2,1}
S1 = = S2 # True
S1! = S2 #false
In/not in:
Arithmetic equivalent to a dictionary
Determine if a value exists

Advantages of collections and dictionaries:
In/not in operator speed is relatively fast

Functions that can be used for a collection:
Len (x), Max (x), Min (x), sum (x), any (x), all (x)

Common collection Methods in Python3:
Methods for Python3 Collections
Methodological significance
S.add (e) Adds a new element e to the collection and does not add if the element already exists
S.remove (e) removes an element from the collection and generates an KEYERROR error if the element does not exist in the collection
S.discard (e) removes an element e from the set S and does nothing when the element e does not exist;
S.clear () empties all elements within the collection
S.copy () make a shallow copy of the collection
S.pop () removes a random element from the set S, or throws a Keyerror exception if this collection is empty
S.update (S2) with S and S2 to get the complete update of the variable s
S.difference (S2) Returns a collection of all elements that exist in S, but not in S2, with the s-s2 operation
S.difference_update (s2) equals S = S-s2
S.intersection (s2) equals S & S2
S.intersection_update (s2) equals s = S & s2
S.isdisjoint (S2) If the intersection of S and S2 is null returns TRUE, non-null returns false
S.issubset (S2) returns true if the intersection of S and S2 is not NULL, and NULL returns false
S.issuperset (...) Returns true if S is a subset of S2, otherwise false
S.symmetric_difference (S2) Returns a symmetric complement, equal to S ^ s2
S.symmetric_difference_update (S2) update s with symmetric complement of s and S2
S.union (S2) generates the complete works of S and S2

Set Derivation:
Combining derivation is an expression that generates a set with an iterative object
Grammar:
{Expression for variable in iterate object [if truth expression]}
Previously said [] within the representative can be omitted
For example:
l= [1, 2, 5, 6, 3, 5, 9, 4, 5]
s = {x for x in L)}
(Derivation nested with list, dictionary consistent)

Fixed set Frozenset:
Is immutable, unordered, and contains a unique set of elements
Used to fix a set of keys that can be used as a dictionary, and also as a value for a collection
constructor function:
Frozenset () creates an empty fixed collection
Frozenset (iterable) creates a fixed collection with an iterative object
For example:
f = frozenset () # Empty fixed collection
f = Frozenset ([1, 3, 5, 7]) # f = Frozenset ({1, 3, 5, 7})
Fixed set operation:
& Intersection, | Set,-complement set, ^ symmetric complement
>, >=, <, <=, = =,! =
In/not in
(Consistent with Set set)
Fixed Collection method:
The method of the collection takes away all the modification methods


                            Summary:

Data type:
Numeric type:
int, float, complex, bool

Container type:
Immutable containers:
STR, tuple, Frozenset, bytes (byte string)
Variable containers:
List, Dict, set, ByteArray (byte group)
Value:
None, False, True
Operator:
Arithmetic operators:
+,-, *,/,//,%, * *
Comparison operators:
<, >, <=, >=, = =,! =
In/not in, is/is not
Boolean operators:
Not, and, or
+ (plus sign),-(minus)
&, ^, | , [] (index)
An expression:
1
1+2
Max (A.)
x if x > y else y (conditional expression)
Three derivation types:
list, dictionary, set derivation (3 kinds)
Statement:
An expression statement:
All statements can be written in a single line, forming a statement
For example:
Print ("Hello World")
1 + 2
Assignment statement:
A = 100
A = b = c = 100
X, y = 100, 200
A[0] = 100
dict ["name"] = "Tarena"
Del statement
While statement
For statement
Break statement
Continue statements
Pass Statement
Function:
Built-in functions: (System built-in functions)
Len (x)
Max (x)
MIN (x)
SUM (x)
Any (x)
All (x)
Constructors: (Used to create data objects of the same type)
BOOL (x)
int (x) (the binary conversion can be added with the input parameter be>=2 and <= 36)
Float (x)
Complex (x)
List (x)
Tuple (x)
STR (x)
Dict (x)
Set (x)
ABS (x)
Round (x)
Pow (x, y, z = None)
Bin (x)
Oct (x)
Hex (x)
Chr (x)
Ord (x)
Range (Star,stop,step)
Input (x)
Print (x)
Help (__BUILTINS__)

That's pretty much what I said before.

Next we talk about the function

Ok everyone before the start I want to say two cough cough:

Before, say, 101 equals 5, right? Maybe a shiver in the hand becomes 011.

Have a careful little friend to send me a comment on the discovery

If you have any questions, you can always comment on it, and I'll respond when I see it.

I'll solve it sometimes.

For example, where do not understand the logic can not make sense ah or more confused is OK

The first 12 lessons are all about common and occasional basics of arithmetic and grammar.

There's a lot of things that you don't understand at once.

We're going to do a real-thing project and learn from the back.

Some of the things that may never be used in a lifetime are not said to be interested friends can see Help in interactive mode

or the official API document translation Good API documentation is OK the first lesson before the article I added the API document address interested can go to download

This project is the Student information management system yesterday's second exercise we've made a start, right?

All right, no nonsense, get to the chase.

Functions: function
A function is a block of statements that can execute a call repeatedly
Role:
1. Used to encapsulate statement blocks to improve code reusability
2. Define user-level functions
DEF creates a function statement:
def function name (formal parameter list):
Statement block
Description
1. The name of the function is the name of the statement block
2. The naming convention for function names is the same as the variable name (name must be an identifier)
3. The function name is a variable (do not assign a value to it easily)
4. The function has its own space, the variables inside the function cannot be accessed outside the function, but the external variables can be accessed
5. function If no incoming parameter is required, the formal parameter list can be empty
6. The statement part cannot be empty, if the empty needs to fill the pass
Return to create a return value statement:
Used in a function to end the execution of the current function, returning the place where the function was called, and returning the reference relationship of an object
return[-expression]
([] representative can omit)
Description
1. A function call is an expression
2. If there is no return statement inside the function, return the None object after the function call is complete
3. If the function needs to return another object, use the return statement
Call to function:
Function name (actual call pass parameter)
(Actual call pass parameter, short argument)
Description
1. An expression when a function is called
2. If there is no return statement inside the function, the return to none object after the function call is complete
3. If the function needs to return another object, use the return statement

Parisgabriel:python Full Stack engineer (0 basics to Mastery) Tutorial 13th

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.