Baptism soul, practice python (5) -- python operator, built-in function, python -- python

Source: Internet
Author: User

Baptism soul, practice python (5) -- python operator, built-in function, python -- python

 

Previously, we mentioned the concept of BIF (built-in function). What is a built-in function? It is a function that has been defined by python. It can be used directly without being manually defined, so what BIF are there?

You can enter this code in the interactive interface (IDLE), note that both sides areDual downlink

dir(__builtins__)

 

You can view the BIF of different python versions.

You can see that there are many differences between python3 and python2. If you want to see which BIF is used, you can directly help () it to read the official documentation, what I want to talk about here is that the official python code actually has very few syntaxes and is basically very simple in English. It is impossible to learn programming without learning English. How should I master the frequently used terms of the development language, in addition, the official documentation is more formal and accurate than any other parsing. You must learn to see the official documentation.

You should have seen the computation at the end of the previous chapter. Yes, any development language can perform computation. You can't use it as a calculator.

Speaking of this, operators are involved:

1. Arithmetic Operators

+,-, ×, Which has been learned in Mathematics

///, //, % Are all related to division, but they represent different. First, there are different results in python2 and python3:

The above is python2 and below is python3./The Division is normal in python2 by default, but the fractional part is removed. If you want to reach the result in python3, that is, the value equals to the value, the following advanced syntax is required:

This [from _ future _ import division] syntax is not mentioned for the moment. It will be mentioned later in the module chapter. You can use this syntax if you know it.

Do you think, wow, it's a pitfall. A simple division operation still cannot get the expected result. Yes, after the python official knowledge, this is also improved to python3.

// Modulo operation, or full budget

% Remainder operation

This remainder operation will play a major role in the future, so we can appreciate it.

 

2. Comparison OPERATOR:

> Greater

> = Greater than or equal

<Less

<= Less than or equal

= (Note that = here is not the same as is)

! = Not equal to (<> it also means not equal)

= Indicates a value (x = y = z chained value assignment)

3. logical operators:

In belongs

Or (note that, unlike other languages, the or here is not the same |, | it has other meanings)

Not in does not belong

Is equivalent

 

I have learned the first three items when I learned a collection in high school mathematics. I don't need to talk about them. You will understand them later.

It is mainly is, which is used to determine whether it is its own usage, for example:

Here, id () is a built-in function that allows you to view the id in the object's memory space. Therefore, it can be used together with is to determine whether it is himself or herself, but it is the same here, it seems that there is no problem, right? Because the results are the same, Do you think = is? No, let's see.

 

Here we use a list of knowledge that we will mention later. Sorry, because the knowledge point is so cross-cutting that we have to mention the list to explain that the current = is not the same as is, I will explain this in detail later.

No. At this time, the returned value of a is B is False, but the id is the same.So = is not equivalent to remembering this.

4. ** Power Operation

5. plus and minus signs:

+,-(This is not the addition or subtraction operation in Arithmetic Operators)

 

You should have doubts now. If these operators are mixed together, how can we calculate them? Who starts computing first, and who finally calculates?

So there is an operational priority:

Yes, this is all the computing priorities. You should think, I rely on it. I have learned a programming language and there are so many priority rules. Do I have to back it up?

No, you don't have to back. You will naturally remember it when writing code to maintain the code, and you don't have to remember it all. This is usually used:

The priority ranges from left to right:

Power Operation (**), positive and negative signs (+,-), Arithmetic Operators (*,/, //, %, +,-), comparison operators (<, <=,>, >=, = ,! =), Logical operators (not, and, or, is)

In fact, these priorities are basically the same as those in mathematics.

Note the following:

The priority of the plus or minus sign on the left of the power operation is lower than that on the right:

 

So far, you have mastered the real preliminary concepts and rules, and will enter the path of true baptism.

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.