The difficulty of the basic knowledge of Python

Source: Internet
Author: User

First, identifiers

(1) Identifiers cannot begin with numbers; identifiers that begin with an underscore have a special meaning and require special attention when used.

Identifiers that begin with a single underscore (such as _foo) represent class attributes that cannot be accessed directly, and are accessed through the interfaces provided by the class and cannot be imported with "from XXX import *".

Identifiers that begin with a double underscore (such as __foo) represent the private members of the class.

Identifiers that begin and end with a double underscore (such as __foo__) represent a special method-specific identifier for Python, such as __init__ (), which represents the constructor of a class.

(2) Identifier letters are case-sensitive, such as "ABC" and "ABC" are two identifiers.

(3) Identifiers prohibit the use of reserved words in Python.

What about reserved words? As follows:

and for expression arithmetic, logic and manipulation
As for type conversion
Asser T assertion, used to determine whether the value of a variable or conditional expression is true
break interrupts the execution of a loop statement
class is used to define classes
continue continue with the next loop
def is used to define a function or method
del Delete the value of a variable or sequence
elif conditional statements are used in conjunction with the IF Else
ELSE Conditional statement conditional statement, used in conjunction with IF,ELIF. can also be used for exceptions and cyclic use
exceptexcept includes action codes after catching exceptions, used in conjunction with try,finally
EXEC for executing python statements
For Loop statement
finally is used for exception statements, and after an exception occurs, always executes the code block that finally contains. Used in conjunction with the Try,except
from for importing modules, using with import
Global Variables defined
If condition statement, used in conjunction with Else,elif
import is used for importing modules in combination with from
in determining whether a variable exists in a sequence
is to determine if a variable is an instance of a class
Lambda defines anonymous functions
not for expression operations, logical non-operation
or used for expression arithmetic, logic, or manipulation
Pass empty class, function, method placeholder
Print Statement
raise exception throw Operation
Return Returns the result of the calculation from the function
try contains statements that may have exceptions, used in conjunction with except,finally
While Loop statement
with simplified Python statements
yield is used to return a value from a function sequentially

Second, the value type

Number, string ' ', list [], tuple (tuple) (,), dictionary (Dictionary) {:}, collection (sets) {,}.

Immutable: string, tuple;

Unordered: dictionary, set;

Cannot be duplicated: A dictionary, a collection.

Efficiency comparison:

Lists > Dictionaries

  

  Notes:

    Numeric type:

Complex (x) converts the x to a complex number, the real number is x, and the imaginary number is 0.

Complex (x, Y) converts X and Y to a complex number, the real part is x, and the imaginary part is Y.

MODF (x) returns the integer part and fractional part of X, the two-part numeric symbol is the same as x, and the integer part is represented by a floating-point type.

    Character type:

Three quotation marks ("' or" ") can identify a multi-line string compared to single or double quotation marks, such as a word wrap, indent, and so on, which are preserved intact.

In special cases, remember to add a backslash (\) to escape, or add a prefix R or R.

Comma (,) can also be used to make the amount of thousands separator, as follows:

        

B, D, O, and X are binary, decimal, octal, hexadecimal, as follows:

        

S.strip (' chars ') returns a new string that is generated by removing the character (' chars ') of the string specified by the tail. The default is remove '.

S.title () turns the first letter of all words into uppercase.

Three, operator

Bitwise operators:

  

    Note: The picture comes from the smart technology of Teddy

The difficulty of the basic knowledge of Python

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.