栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python基础学习-03

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/580600.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号