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

How to use arithmetic operators in Python

2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

I believe many inexperienced people don't know what to do about how to use arithmetic operators in Python. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Code implementation

A = 10 + 5 # calculate print ("1, a =", a) a = 'hello' +' + 'world' # string print ("2, a =", a) a = 10-5 # calculate print ("3, a =", a) a = 5-Trueprint ("4, a =", a) a = a-2 # subtract 2 from the value of the variable a Then assign it to aprint ("5, a =", a) a = 5 * 5print ("6, a =", a) a = 10 / 5print ("7, a =", a) a = 5 / 2print ("8, a =", a) a = 10 / 3print ("9, a =", a) a = 10 / / 3print ("10, a =", a) a = 5 / 2print ("11, a =", a) a = 2 * * 2print ("12, a =") A) a = 10 * * 5print ("13, a =", a) a = 16 * * 0.5 # find the square root of 16 print ("14, a =", a) a = 10% 5 # 0print ("15, a =", a) a = 10% 4 # 2print ("16, a =", a) a = 10% 3 # 1print ("17, a =", a) a = 10% 2 # 0print ("18, a =", a)

Code run output:

1. A = 15

2. A = hello world

3. A = 5

4, a = 4

5. A = 2

6. A = 25

7, a = 2.0

8, a = 2.5

9, a = 3.33333333333335

10, a = 3

11, a = 2

12, a = 4

13, a = 100000

14, a = 4.0

15, a = 0

16, a = 2

17, a = 1

18, a = 0

Program analysis

# arithmetic operator

# + addition operator (if the addition operation is performed between two strings, the string operation will be performed)

#-subtraction operator

# * multiplication operator (if you multiply a string by a number, the string is copied, repeating the string a specified number of times)

# / division operator, the result always returns a floating-point type

# / / divisible, only the calculated integer bits are retained, and an integer is always returned

# * * exponentiation to find the powers of a value

Take #% module to find the remainder of the division of two numbers

After reading the above, have you mastered how to use arithmetic operators in Python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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: 294

*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

Internet Technology

Wechat

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

12
Report