Python language and its application-knowledge point traversal

Source: Internet
Author: User

Traversing Python syntax

2. Basic elements: numbers, strings, and variables

What are the basic types of 2.1 python?
Boolean (True, False), Integer (42,100000), floating-point (3.14159,1.0e8), String ("string")

All data in 2.2 Python is in the form of an object.
The object is the data entity, and the variable is the name. The object has the type, the basic is above several, the object also is divided the constant and the variable.

2.3 Variable Assignment (=)?
Assignment is not equal to copy, variable assignment simply takes a name for the data object, and the name is a reference to the object instead of the object itself.
The variable name is the name associated with the actual data, and the meaning of the variable exists is to make it easy to refer to the memory value, and at compile time the variable name is replaced with the address.

2.4 How do I see the type of an object? Type () statement

2.5 python numbers (integer and floating point) operations?
+ 、-、 *,/(floating point except),//(integer except),% (redundancy), * * (Power), Divmod ()

2.6 Cardinality in Python
0b/0b binary, 0o/0o octal, 0x/0x hex

2.7 type conversion, length view (all built-in functions, not attached to objects, can be used directly)
int (), float (), str (), bool (); Len ()

2.8 Python3 The reason for separating from the Python2?
Unicode

2.9 String type?
The first sequence type, essentially a sequence of characters, is immutable (the same tuple, not directly inserted, deleted, and changed elements).

2.10 Create a string?
Single or double quotation mark creation (the string that the interactive interpreter output is always enclosed in single quotes), and a three-hyphen (single-pair) quotation mark creates a multiline string.

Output format of the 2.11 print function
Print captures the outermost quotation marks, outputs the actual content directly, and automatically adds a space between the output sections, and all outputs add a newline character at the end. (Print output format can be set)

2.12 String manipulation: stitching, copying, extracting, single character substitution
"+" splicing string constants and variables, directly placed can be spliced string constants, "*" can do string multiplication, do copy; "[]" can extract characters by offset, can be extracted from the beginning [0][1][2], or can be extracted from the tail [ -1][-2] (cannot exceed the maximum limit). "Obj.replace (' obj ', ' C ')" can be used to replace a single character of a string.

2.13 Shard Operation [Start:end:step]
[:] extracts the entire string; [Start:] from start to end; [: end] From the beginning to the END-1 (special attention); [Start:end] from start to end-1;[start:end:step] from start to End-1, Extract one per step character.
An offset of 0 is the beginning;-1 is the end; step is negative or reverse.

2.14 member functions of the String object: Split (), join (),
String.Split ("string" or ' C ') divides the string into a list of substrings by delimiter [].
("string" or ' C '). Join (list) reverse operation
String.startwith ("string"); String.endwith ("string"); String.find ("string"); String.rfind ("string"); String.count ("string"); String.isalnum ().
String.strip ("."); String.capitalize (); String.title (); String.upper (); String.Lower (); String.swapcase (); String.center (30); String.ljust (30); String.rjust (30).

2.15 String substring substitution: replace ()
The String.Replace ("obj", "C", num) functions have three parameters, and the third one is the maximum number of replacements. function is less powerful than regular expressions.

3. Containers: Lists, tuples, dictionaries, and collections

The data is split and merged into a specific form.
3.1 Sequence structure string, tuple, list (the first two immutable) (the latter two do not require the same type of elements)

3.2 Create List [] list[] List derivation (ordered list, element repeatable)

3.3 Conversion between data Structures list (), tuple (), Dict (), set ()
List () converts a string, a tuple into a list, split () splits a string into a list, and a join can form a string

3.4 using [subscript] to get list elements [0][1][2], [ -1][-2][-3];

3.5 The list can contain arbitrary elements, so the list can be nested list, [[],[],[]], the general nesting of two layers is sufficient, similar to two-dimensional array.

3.6-Slice extraction elements: [Start, end, step]

3.7 member functions for list objects: List.append (Var) (add element at the end), List.extend (var) (+ =) (Consolidated list), List.insert (Num, var) (insert element at specified position), List.remove ( Value) (delete the specified value element), List.pop (1) (Gets and deletes the specified position element, where pop () ==pop ( -1)), List.index (value) (the location of the query for a specific value element), List.count (value) (count the number of occurrences of the specified value in the list), List.sort (reverse=true) (sorted list, the list will change, you can set the sort direction),

3.8 Python statement Operation list: Del statement, Del List[num]; In statement (judging if the value is in the list),

3.9 python functions: sorted () sort; Len () gets length; = (Assignment); copy () (copy); (the assignment is not coupled, there are multiple methods of copying, list (), slice)

3.10 Create tuples: () create empty tuples; tuples are created and tagged with commas, commas cannot be saved, brackets are allowed;

3.11 You can assign a tuple to multiple variables and unpack the tuple;

3.12 Creating a dictionary: {} Creating an empty dictionary; adding elements;

3.13 Dict () can convert any two-value subsequence into a dictionary (nested), dict.clear () Delete all elements, Dict.get (key, return), Dict.keys () Get all keys, dict.values () Get all values ; Dict.items () Get all key value pairs; dict.copy () copy;

3.14 Dictionary member functions: Dict.update (DICT) merged dictionary;

3.15 del deletes the specified key element; In determines whether the key exists;

3.16 Create collection: Set () creates an empty set; {n/a} creates a collection;

3.17 Set operation: intersection &; set |; difference sets--------^;<= judgment whether the subset of the >=, whether the super;> judgment is really super-set;

3.18 Summary: [] Create a list; Create a tuple by commas; {} create a dictionary; Note: Because of the dictionary's attributes, lists, dictionaries, and collections cannot be keys to the dictionary; tuples can; and immutable constants.

Python language and its application-knowledge point traversal

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.