Python3 basic operator overview, python3 operator Overview

Source: Internet
Author: User

Python3 basic operator overview, python3 operator Overview

This article describes the basic operators of Python3, which are essential for learning Python. The details are as follows:

First, most operators in Python are similar to those in C, but there are many differences. The operators in Python 3 are listed here.

I. Arithmetic Operators

Note:

Double slash // division is always rounded down.
The conversion from the number of runes to the integer may be rounded or truncated. math. floor () and math. ceil () are recommended for Explicit conversions.
Python defines pow (0, 0) and 0 ** 0 is equal to 1.

Ii. Comparison Operators

Operator Description
< Less
<= Less than or equal
> Greater
> = Greater than or equal
= Equal
! = Not equal
Is Determine whether two identifiers are referenced from an object
Is not Determine whether two identifiers reference different objects

Note:

The eight comparison operators have the same priority.

Python allows chained comparison like x <y <= z, which is equivalent to x <y and y <= z.
The plural values cannot be compared, but can only be compared to equal values.

Iii. logical operators

Operator Description Remarks
X or y IfXIs false, thenY, ElseX
X andy IfXIs false, thenX, ElseY
Not x IfXIs false, thenTrue, ElseFalse

Note:

Or is a short-circuit operator. It calculates the value of the second operation only when the first operation is False.
And is also a short-circuit operator. It calculates the value of the second operation only when the first operation is True.
Not has a lower priority than other operators. Therefore, not a = B is equivalent to not (a = B), and a = not B is incorrect.

Iv. bitwise operators

Operator Description Remarks
X | y Bitwise OR operator
X ^ y Bitwise OR operator
X & y Bitwise AND operator
X <n Left moving Operator
X> n Right moving Operator
~ X Bitwise Inverse Operator

V. assignment operators

Compound assignment operators correspond to Arithmetic Operators one by one:

Vi. member operators

Python provides a member operator to test whether an element is in a Sequence.

Operator Description
In If a value is found in the specified sequence, True is returned; otherwise, False is returned.
Not in If no value is found in the specified sequence, True is returned; otherwise, False is returned.

In python33, how does one perform operations between two different lists?

I am from python2.7.5, and I don't know if 3.3 is applicable! Try:

Python33

Import collectionsdef tester (ts): outfmt = "HOT days: % (HOT) d," \ "COMFORT days: % (COMFORT) d," \ "cold days: % (COOL) d, "\" average temperature: % (avg ). 1f "category = lambda t:" COOL "if t <60 else (" HOT "if t> 85 else" COMFORT ") counter = collections. counter (map (category, ts) print outfmt % dict (avg = 1. * sum (ts)/len (ts), ** counter) tester ([55, 62, 68, 74, 59, 45, 41, 58, 60, 67, 65, 78, 82, 88, 91, 92, 90, 93, 87, 80, 78, 79, 72, 68, 61, 59])

Related Keywords:

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.