python基础学习-03

python基础学习-03

# Python number

# Python There are three types of numbers
"""
int
float
complex
"""
x = 1    # int
y = 2.8  # float
z = 1j   # complex

# If you want to verify the type of a variable,you can use the type() function
print(type(x))
print(type(y))
print(type(z))

# int
# int integer,is a integer.It could be positive or negative,no decimal,and unlimited length.
x = 1
y = 3562254887
z = -35522
print(type(x))
print(type(y))
print(type(z))

# float
# It could be contains decimal places,and could be positive or negative.
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))

# scientific notation
x = 35e3
y = 12E4
z = -87.7e100
print(type(x))
print(type(y))
print(type(z))
# unreliable figure
# It has "J" as the imaginary part
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))

# type conversion
x = 1    # int
y = 2.8  # float
z = 1j   # complex
a = float(x)
b = int(y)
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))

# random number
# python有一个内置模块random可以用来生成随机数
# 示例:导入random模块,并显示1到10之间的一个随机数:
import random
print(random.randrange(1,11))

"""
Test
x 转换成浮点数
1.x = 5
x = float(x)

x 转换成整数
2.x = 5.5
x = int(x)

x 转换成复数
3.x = 5
x = complex(x)
"""
x = 5
x = float(x)
print(x)
print(type(x))
x = 5.5
x = int(x)
print(x)
print(type(x))
x = 5
x = complex(x)
print(x)
print(type(x))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七七高7777

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值