Python之数字
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Helvetica Neue"; color: #000000 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "PingFang SC"; color: #000000 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Helvetica Neue"; color: #fa2500 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Helvetica Neue"; color: #000000; min-height: 16.0px }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "PingFang SC"; color: #fa2500 }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Helvetica Neue"; color: #005493; min-height: 16.0px }
p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "PingFang SC"; color: #005493 }
span.s1 { }
span.s2 { font: 18.0px "Helvetica Neue"; color: #fa2500 }
span.s3 { font: 18.0px "PingFang SC"; color: #fa2500 }
span.s4 { font: 18.0px "Helvetica Neue" }
span.s5 { font: 14.0px "PingFang SC" }
span.s6 { font: 14.0px "Helvetica Neue" }
span.s7 { color: #000000 }
span.s8 { font: 14.0px "Helvetica Neue"; color: #000000 }
span.s9 { color: #fa2500 }
span.s10 { font: 14.0px "PingFang SC"; color: #fa2500 }
span.Apple-tab-span { white-space: pre }
int(数字)===>在Python3中,int没有范围,在Python2
中,int
超出范围就叫长整型(Long)。
a:加法(+)
eg:age = 25
a1 = 10
a2 = 20
a3 = a1 + a2
b:减法(-)
eg:age = 25
a1 = 10
a2 = 20
a3 = a1 - a2
c:乘法(*)
eg:age = 25
a1 = 10
a2 = 20
a3 = a1 * a2
d:除法(/)
eg:age = 25
a1 = 10
a2 = 20
a3 = a1 / a2
补充:
a1 = 39 / 8
print(a1)===>4.975
a2 = 39 // 8
print(a2)===>4
(//)的意思是整除,取商,不取小数。
e:平方(**)
eg:a1 = 2 ** 4
意思是:2的4次方
f:取余(%)
eg:a1 = 39 % 8
意思是:39除以8的余数
g:将数字的字符串转换成数字类型
input = “10”
new_input = int(input)
print(new_input *10)
h:base转换进制2、8、10、16
eg:a = “m”
b = int(a, base=16)
print(b)
意思是将字符m转换成16进制,并打印16进制的结果。
i:bit_length( ) 当前数字的二进制,至少用n位表示。
问题1:判断奇偶数
a = 35
temp = a % 2
if temp == 0:
print(“偶数”)
else:
print(“奇数”)
问题2:输出1-100内所有的奇数、偶数
(1)奇数:n = 1
while n < 101:
temp = n % 2
if temp == 0:
pass
else:
print(n)
n = n + 1
print(“———end———”)
(2)偶数:n = 1
while n < 101:
temp = n % 2
if temp == 0:
print(n)
else:
pass
n = n + 1
print(“———end———”)
原文地址:https://www.cnblogs.com/george92/p/8495340.html