Python3 Exercises Series (06)--Summary of various symbols

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise bitwise operators logical operators

Summary of the various symbols in Python3 1 keywords

Import keyword

Print (keyword.kwlist, end= ' \ t ')

[' False ', ' None ', ' True ', ' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' fi Nally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' nonlocal ', ' not ', ' or ', ' Pass ', ' raise ', ' return ', ' Try ', ' while ', ' with ', ' yield ']

2 Data type:

Ref: 75578754

Type

Meaning

Example

Int

Integral type

1

Float

Floating point Type

1.0

bool

Boolean value

True or False

Complex

Plural

A+bj

String

String

' Abc123 '

List

List

[A,b,c]

Tuple

Meta-group

(A,B,C)

Set

Collection

{A,b,c}

Dictionary

Dictionary

{A:B,C:D}

Complex the imaginary part of a complex number cannot be omitted

string string cannot include a ' \ ', otherwise the output is not the original string

List and tuple list elements can be modified, tuple no, but the tuple can include list multiple data types, more resources than list

Set no sequential order and no duplicate elements

Dictionary A key corresponds to multiple values, but cannot have the same key

3 Escape characters

Reference: http://blog.sina.com.cn/s/blog_777e04300102x8mn.html

Escape character

Describe

\ (at end of line)

Line continuation character

\\

Backslash symbol

\‘

Single quotation marks

\"

Double quotes

\a

Bell

\b

BACKSPACE (Backspace)

\e

Escape

\000

Empty

\ n

Line break

\v

Portrait tab

\ t

Horizontal tab

\ r

Enter

\f

Page change

\oyy

Octal number yy represents the character, for example: \o12 represents a newline

\xyy

The decimal number yy represents the character, for example: \x0a represents a newline

\other

Other characters are output in normal format


4. String formatting

Reference: http://blog.sina.com.cn/s/blog_777e04300102x8mn.html

%% percent Sign # is to output a%

%c characters and their ASCII Code

%s string

%d signed integer ( decimal)

%u unsigned integer ( decimal)

%o unsigned integer ( octal)

%x unsigned integer ( hexadecimal)

%x unsigned integer ( 16 uppercase characters)

%e floating-point numbers ( scientific notation)

%E floating-point numbers ( scientific notation, E instead of e)

%f floating point number ( with decimal point symbol)

%g floating-point numbers ( %e or%f depending on the size of the value )

%G floating-point numbers ( similar to%g)

%p pointer ( memory address of the value printed in hexadecimal)

%n stores the number of output characters into the next variable in the parameter list

% The format character can also be used in dictionaries,% (name) available references the elements in the dictionary to format the output.

5 Arithmetic operators

Excerpt from:http://www.runoob.com/python3/python3-basic-operators.html

5.1 Python arithmetic operators

Operator

Describe

Instance

+

Add-Two objects added

A + B output result 31

-

Minus-get negative numbers or one number minus the other

-B Output Result-11

*

Multiply by two number or return a string that is repeated several times

A * b output result 210

/

Except-X divided by Y

B/A Output Results 2.1

%

Modulo-Returns the remainder of the division

B% A output result 1

**

Power-Returns the Y power of X

A**b is 10 of the 21-time Square

//

Divide-Returns the integer part of the quotient

9//2 output result 4, 9.0//2.0 output 4.0

@ Matrix operator

5.2 Python comparison operators

Operator

Describe

Instance

==

Equals-compares objects for equality

(A = = B) returns FALSE.

!=

Not equal-compares two objects for unequal

(A! = b) returns TRUE.

>

Greater than-returns whether x is greater than Y

(A > B) returns FALSE.

<

Less-Returns whether x is less than Y. All comparison operators return 1 for true, and return 0 for false. This distinction is equivalent to the special variable true and false. Note that these variable names are capitalized.

(A < b) returns TRUE.

>=

Greater than or equal-returns whether X is greater than or equal to Y.

(a >= B) returns FALSE.

<=

Less than or equal-returns whether X is less than or equal to Y.

(a <= B) returns True.


5.3 Python assignment operator

Operator

Describe

Instance

=

Simple assignment operator

c = A + B assigns the result of the operation of A + B to c

+=

Addition assignment operator

c + = A is equivalent to C = C + A

-=

Subtraction assignment operator

C-= A is equivalent to C = c-a

*=

Multiplication assignment operator

C *= A is equivalent to C = c * A

/=

Division assignment operator

C/= A is equivalent to C = c/a

%=

Modulo assignment operator

C%= A is equivalent to C = c% A

**=

Power assignment operator

C **= A is equivalent to C = c * * A

//=

Take the divisible assignment operator

C//= A is equivalent to C = c//A

5.4 Python bitwise operators

Operator

Describe

Instance

&

Bitwise AND Operator: Two values that participate in the operation, if two corresponding bits are 1, the result of that bit is 1, otherwise 0

(A & B) Output result 12, binary interpretation: 0000 1100

|

Bitwise OR operator: As long as the corresponding two binary has one for 1 o'clock, the result bit is 1.

(A | b) output result 61, Binary interpretation: 0011 1101

^

Bitwise XOR Operator: When two corresponding binary differences, the result is 1

(a ^ b) output result 49, binary interpretation: 0011 0001

~

Bitwise inverse operator: each bits of the data is reversed, that is, 1 is changed to 0, and 0 to 1. ~x similar to -x-1

(~a) Output result-61, Binary interpretation: 1100 0011, in the complement form of a signed binary number.

<<

Left move operator: The operands of the operands all shift left several bits, the number of "<<" to the right to specify the number of bits moved, high drop, low 0.

A << 2 output results 240, binary interpretation: 1111 0000

>>

Right move operator: Move all the binary of the left operand of ">>" to the right of several bits, and the number to the right of ">>" to specify the number of bits to move

A >> 2 output results 15, binary interpretation: 0000 1111


5.5 Python logical operators

Operator

Logical Expressions

Describe

Instance

and

X and Y

Boolean "and"-if x is False,x and y returns FALSE, otherwise it returns the computed value of Y.

(A and B) returns 20.

Or

X or Y

Boolean "or"-if x is True, it returns the value of x, otherwise it returns the computed value of Y.

(A or B) returns 10.

Not

Not X

Boolean "Non"-returns False if X is True. If X is False, it returns TRUE.

Not (A and B) returns False


5.6 Python Member operators

Operator

Describe

Instance

Inch

Returns False if the value found in the specified sequence returns True.

x in the y sequence, if X returns True in the y sequence.

Not in

Returns True if no value is found in the specified sequence, otherwise False.

X is not in the Y sequence if x does not return True in the y sequence.


5.7 Python identity operator

Operator

Describe

Instance

Is

is to determine whether two identifiers are referenced from an object

x is y, similar to ID (x) = = ID (y) , returns True if the same object is referenced, otherwise False

is not

Is does not determine whether two identifiers are referenced from different objects

x is not y, similar to ID (a)! = ID (b). Returns True if the reference is not the same object, otherwise False is returned.


5.8 Python operator Precedence

Operator

Describe

**

Index (highest priority)

~ + -

Bitwise flip, unary Plus and minus (the last two methods are called [email protected] and [email protected])

* / % //

Multiply, divide, modulo, and divide

+ -

Addition subtraction

>> <<

Shift right, left shift operator

&

Bit ' and '

^ |

Bitwise operators

<= < > >=

Comparison operators

== !=

equals operator

= %= /= //= -= += *= **=

Assignment operators

Is isn't

Identity operator

In No in

Member operators

And Or not

logical operators

Python3 Exercises Series (06)--Summary of various symbols

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.