Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between the Python operators * * and *

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the Python operator * * and * what is the difference between the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will gain after reading this Python operator * * and * what difference article, let's take a look at it.

We know that * * stands for power.

如下>>>12 * 12144>>>12 ** 2144>>>a=1e200>>> a1e+200>>>a ** 2Traceback (most recent call last):File "", line 1, in OverflowError: (34, 'Result too large')>>>a * ainf>>>a = 100 ** 100 # python3中int整型一般不会溢出,取决于内存100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000>>>a * a,a ** 2 # 两种方式都没问题,int很大,不会溢出,取决于内存(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)>>>float(a) * float(a) #float用这种方法, Nor will it overflow inf > float (a) * * 2 # float may overflow in this way, pay attention! Traceback (most recent call last): File "", line 1, in OverflowError: (34, 'Result too large') / and / / main differences:

The result of the / / operator is minimum rounded, and the / operator retains the decimal places

Supplement: operators and their precedence in python3

1. General operator:

+-* / (true division)% / / (floor division-floor) * * (exponentiation)

two。 Assignment operator:

=

3. Enhancement operator (enhancement assignment operator)

+ =-= /% = * / / =

Aefficiency 1 (high efficiency)

A=a+1 (low operating efficiency)

4. Boolean operator (comparison operator)

= = >

< >

= 2 > 1

True

3 > 2 and 2 > 1

True

5. Logical operator

Not and or priority:

Not has the highest priority

And

Or has the lowest priority

6. Bit operator

Bit: every bit in binary

>: shift operator

&: logical summation

|: logical OR

~: logic is wrong.

^: logical difference OR

7. Ternary operator

Variable = (value 1 if Boolean expression else value 2)

Returns a value of 1 if the Boolean expression bit is true, otherwise returns a value of 2

Among operators, ternary operators have the lowest precedence.

1. Multiply and divide first and then add and subtract

two。 Exponentiation has the highest priority

3. The ternary operator has the lowest precedence

4. The less the number of elements, the higher the priority

Exponentiation: unary operator

5. Priority from highest to lowest:

Power operation

Plus or minus sign

Arithmetic operator (- = * /)

Comparison operator

< >

=)

Logical operator (not and or)

This is the end of the article on "what's the difference between Python operators * * and *". Thank you for reading! I believe you all have a certain understanding of the knowledge of "what is the difference between Python operator * * and *". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report