Common operators for basic python tutorials and basic python tutorials

Source: Internet
Author: User

Common operators for basic python tutorials and basic python tutorials

Python operators are similar to those in other languages.

(Currently, we only know the basic usage of these operators, so that we can expand the following content. Advanced applications are not introduced at the moment)

Mathematical operations
Copy codeThe Code is as follows:
>>> Print 1 + 9 # Addition

>>> Print 1.3-4 # Subtraction

>>> Print 3*5 # Multiplication

>>> Print 4.5/1.5 # Division

>>> Print 3 ** 2 # multiplication party

>>> Print 10% 3 # Calculate the remainder

Judgment

Returns True/False if it is True or False.
Copy codeThe Code is as follows:
>>> Print 5 = 6 #=, equal

>>> Print 8.0! = 8.0 #! =, Not equal

>>> Print 3 <3, 3 <= 3 # <, less than; <=, less than or equal

>>> Print 4> 5, 4> = 0 #>, greater than; >=, greater than or equal

>>> Print 5 in [1, 3, 5] #5 is an element of list [1, 3, 5 ].


(There are also is, is not, and so on, not in-depth)

Logical operation

Operation between True and False
Copy codeThe Code is as follows:
>>> Print True and True, True and False # and, "and", both are True.

>>> Print True or False # or, "or" operation. If one of them is True, it is True.

>>> Print not True # not, non operation, Inverse Operation

It can be used with the previous part to do some exercises, such:
Copy codeThe Code is as follows:
>>> Print 5 = 6 or 3> = 3

Summary

Mathematics +,-, *,/, **, %

Judgment = ,! =,>,> =, <, <=, In

Logic and, or, not


In the Basic python tutorial, the % number can be reloaded as the format

Operator Overloading means that the same operator performs different operations in different environments. For example, the percent sign of python is an operator, which plays a different role in different situations. The concept of Operator Overloading is described more in the C ++ book.

One is to calculate the remainder, which takes effect when an integer is encountered.
5 divided by 3, the remainder is 2 5% 3 => 2

Two types are formatted strings.
The % in the string in python is similar to that in C:
C language x = 10
Printf ("a = % d \ n", x)
Python x = 10
Print "a = % d" % x

The and, or, and not operators in python cannot be understood.

The simple explanation is:
And-> A and B-> indicates that both A and B must be satisfied.
Or-> A or B-> indicates A or B. either of the two satisfies one.
Not A-> if A is true, it is false. If A is false, it is true.

In fact, this is not very relevant to Python. It is related to your lack of understanding of the basic logic in programming languages.
This logic applies to many languages. It is also in line with human logic.

If you are interested, go and see:
[Tutorial] Getting started with Python Development

(No address is provided here. Search for the title by google to find the address)

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.