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

1.1 python中定义变量与数据类型

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

1.1 python中定义变量与数据类型

一、定义变量
1.定义变量

语法:变量名=值

2.使用变量

3.看变量的特点
# 定义变量:存储数据TOM
my_name = 'TOM'
print(my_name)
# 定义变量:存储数据 Serendipity
schoolName = 'Serendipity'
print(schoolName)
二、数据类型
数值:int(整型),float(浮点型)
布尔型:true(真),false(假)
str(字符串),list(列表),tuple(元组),set(集合),dict(字典)
1.按经验将不同的变量存储不同的类型的数据
2.验证这些数据到底是什么类型--检测数据类型--type(数据)
# int--整型
num1 = 1
# float--浮点型(小数)
num2 = 1.1
print(type(num1))
print(type(num2))

# str--字符串,特点:数据都要带引号
a = 'Hello world'
print(type(a))

# bool--布尔型,通常判断使用,布尔型有两个数值True和False
b = True
print(type(b))

# list--列表
c = [10, 20, 30]
print(type(c))

# tuple--元组
d = (10, 20, 30)
print(type(d))

# set--集合
e = {10, 20, 30}
print(type(e))

# dict--字典--键值对
f = {'name': 'TOM', 'age': '18'}
print(type(f))

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/755104.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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