The second chapter of the "0 pressure python" knowledge point induction

Source: Internet
Author: User
Tags integer division

Chapter II (number) knowledge points induction

The simplest way to generate very large numbers is to use the power operator, which consists of two asterisks (* *).

Such as:

In Python, integers are absolutely accurate, which means that no matter how big it is, plus 1 will get a new value. You will see that the floating-point number is not.

The equality operator (= =), which results in true or False, are special reserved words, called keywords, which means they have special predefined meanings in the Python language.

This "Infinity integer" feature of Python is great, allowing you to handle incredibly large numbers with absolute precision. such as: Google (googol). In mathematics, Google (googol) refers to 10 of the 100-time square, which is almost unimaginable.

Although Python supports a large number of integers, there is an upper limit, not Python, but the computer hardware (size and speed). It must be admitted that this ceiling is not clear, but certainly much larger than Google, such as:

Google-plex is 10 of the power of Google, it is easy to say: 10 * * (10 * * 100), but do not try to calculate it! If you print it out, it's a 1 followed by Google 0! More atoms than the whole universe, which goes far beyond the power of the computer.

The remainder operator (%) x% y, the symbol depends on Y, one is float, and the result is float.

Scientists estimate that the entire universe of elementary particles (including electrons, protons, neutrons, etc.) is about 1080

It is estimated that the entire Earth has only a "7.5" of sand. X 1018

It is estimated that the entire universe is about 1026 meters in diameter.

So, which physical commonsense is closest to Google?

Is the density of the universe (in kilograms/cubic meters) when the Big Bang (more accurately, the Planck time after the Big Bang). This number is 1096, but it's still smaller than Google.

Division (/), whether or not an integer, evaluates to float type

Integer division (//), when two operands are integers, the result is automatically rounded down to the nearest whole number. In other words, the result of X//y is the largest integer that is less than x/Y. Of course, the operand can also be a floating-point class.

To specify a floating-point format, simply use a decimal point.

You can combine both an integer expression and a floating-point expression. Python will raise the integer expression to a floating-point number.

The precision of floating-point numbers is limited, generally 10-16.

Python uses a 53-bit binary to represent the decimal part of a floating-point number.

Floating-point values range from 10308-10308

For large floating-point numbers (or floating-point numbers that are very close to 0.0), Python will use scientific notation.

4.3 e-3, representing 4.3 x 10-3

9.6 E 5, indicating 9.6 x 105

When a number is used as a count or index, it must be an integer.

A variable is simply a name that is given a data value. In Python, a variable can point to any type of data at any time, because there is no type, and only the data object has a type.

These code functions are as follows:

(1) The variable name A is associated with the value 1

(2) The variable name B is associated with the value 2

(3) Add the variables A and B representing 1 and 2, respectively. Python reacts as if you were typing 1+2.

You must create it before using a variable, but when you assign a value to a variable, it is created if the variable is not created.

Their role is to associate both the name X and the My_amount with the data value 10

What happens if you re-assign a value to a variable?

First, the value on the right is calculated;

Second, the association of the undo variable with the previous value;

Now, the value associated with the variable equals = to the right.

In Python, assignment is a statement.

Python names are case-sensitive.

As for variable names, the rules are as follows:

(1) The first character of the variable name (and other symbol names) must be an underscore or a letter, not a number;

(2) Other characters can be underscores, letters, or numbers.

Unary two-time equation, 0 = ax2+bx+c, and solution formula:

The two-time equation for the golden ratio is defined as: A/b equals (a+b)/A. One of the properties of the golden ratio is that it is 1 smaller than its square. X2 = x + 1, thus available, 0 = x2–x-1.

python treats each variable as a reference. The key is that when multiple variables point to the same value, they do not store the value separately.

If you assign a new value to one of the variables, it points to the new memory unit. Such as:

c = 10

While you can do whatever you want, it is often a bad programming practice to have the same variable point to different types of data. Ideally, as long as you look at the variable name, the programmer knows what kind of data it is pointing to. To determine the type, you can use the built-in function type (), but you cannot determine its type by looking at how the variable is declared in the program.

Programming with Python is to adhere to specific variable naming conventions, and the readability of the code will be much higher.

(1) xxx_str (that is, any variable name that contains str) and S1, S2, S3, and so on, all store text string types.

(2) xxx_list (that is, any package containing the variable name of list), which stores the type of the listing.

(3) x, Y, Z, all stores floating point numbers

(4) Other letters except X, Y and Z, Yuchun are i,j,k and M, all store integers.

If the variable name does not belong to the above type, it is usually stored as an integer.

The purpose of a function can usually be learned by the active words contained therein, such as Convert_to_centigrade ()

Multi-objective assignment:

sequence Assignment: the assignment number to the left is a tuple or list; the right is a tuple or list or string

shortcut to operator:

+ = = *=/= **=//=%= to be aware, these operators are not expressions, but complete statements.

About + + and--using them in Python does not result in grammatical errors, but it does not have any effect. Because Python supports the monocular operator + and-, where-the function is to reverse the notation of the operand, and + has no effect.

The second chapter of the "0 pressure python" knowledge point induction

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.