Revisiting Python Basics - Numbers

Learn Python easily 2022-11-08 04:26:23 阅读数:471

revisitingpythonbasicsnumbers

哈喽,兄弟们,This article takes you to reviewPythonnumber in base.

在编程中,Numbers are often used.in some calculation problems,Or other visual data, etc.PythonThey can be handled according to different usages

1、整数

在PythonYou can perform addition, subtraction, multiplication and division operations on integers(+ - * /),Use two multiplication signs to express powers(**)

a=3
b=4
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a**b)

运行结果

7
-1
12
0.75
81

2、浮点数

PythonConvert all numbers with decimals to floats.There is no need to consider its behavior when working with floating point numbers.Just enter the number you want to use,Python通常会按照你期望的方式处理它们:

a=3.5
b=4.9
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a**b)

运行结果

8.4
-1.4000000000000004
17.150000000000002
0.7142857142857142
463.37587307179774

The number of decimal places the result contains cannot be determined,The book says don't worry,This is the case in all languages.It can be processed later by means of extra decimal places.

3、整数和浮点数

将任意两个数相除,结果总是浮点数.

a=10
b=2
print(a/b)

#运行结果

5.0

兄弟们学习python,有时候不知道怎么学,从哪里开始学.掌握了基本的一些语法或者做了两个案例后,不知道下一步怎么走,不知道如何去学习更加高深的知识.
那么对于这些大兄弟们,我准备了大量的免费视频教程,PDF电子书籍,以及源代码!You can pick it up directly from the business card at the end of the article~
还会有大佬解答!

4、数中的下划线

When writing large numbers, use underscores to group them.

a=100_000_000_0
print(a)

运行结果

1000000000

When printing such an underlined number,and will not print underscores.Because of the storage time of this number,Python会忽略其中的下划线.

同时给多个变量赋值
给多个变量赋值,有助于缩短程序,提高可读性.

a=10
b=12
c=9
print(a,b,c)
a,b,c=0,5,0
print(a,b,c)

运行结果

10 12 9
0 5 0

最后给大家分享一些Python教程,希望对大家有所帮助哈~

Python零基础入门全套教程

Python进阶全套教程

Python实战100例

今天的分享就到这里结束了,谢谢大家观看!

版权声明:本文为[Learn Python easily]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/312/202211080408576093.html