PythonStudy——数据类型 Type of data
数据类型:信息存在的状态
为什么要来描述事物的具体状态:不同的事物需要不同的状态加以描述可以达到描述的最优化
python中有哪些常见的数据类型
1.整型
num = 100000000000000000000000000000000000000000000000000
print(num, id(num), type(num))
print(num - 1) Output:
100000000000000000000000000000000000000000000000000 1628988224880 <class 'int'>
99999999999999999999999999999999999999999999999999
##py3 存储超大数时,超出单位内存大小的部分使用的是字符串形式存储
2.浮点型
salary = 88888.0123456789
print('%015.6f' % salary) info = '%015.6f' % salary
print(info) Output:
00088888.012346
00088888.012346
1)%f对浮点型数据进行占位
2).后的数据数字表示小数精度
3).前的数据是输出的长度,小于等于要输出的数据长度不起作用,超出就采用规定的最大长度
注:%015.6f:右对齐,左侧不足拿0填充, %-15.6f: 左对齐输出
# # # # # # # # 可以将格式化的结果进行保存,以便之后再次使用
3.bool类型: True | False
result = False print(result)
4.str类型: ' ' | " " | """ """ | '' ' ' ''
height = '180cm' print(height, type(height))
height = "180cm" print(height, type(height))
height = """180cm"""
print(height, type(height)) Output:
180cm <class 'str'>
180cm <class 'str'>
180cm <class 'str'>
原始信息:
# '''
# 信息:
# name: Bob
# age: 18
# ''' name = input('name: ')
age = input('age: ')
# # %s是万能占位符, %是用来连接有占位符的字符串与需要占位的变量,多个变量用()包裹 info = """信息:name: %s
age: %s""" % (name, age)
print(info)
Output:
信息:
name: Bob
age: 18
# 有些数据不是以一个值出现,如果用一个变量存放多个值
5、list类型
1.是一个可以存放多个值的容器
2.列表有编号,从0开始标号,对应数据是从左往右 => 列表名[索引]
ls = [3, 1, 2]
num = 3
print(ls, id(ls))
print(ls[0], id(ls[0]))
print(id(num))
print(num is ls[0])

重点:list存放值的方式 => id(num) is id(ls[0])
# # 嵌套
ls = [[1, 2, 3], [4, 5, 6], [7, 8, [9]]]
# # 在嵌套下,获取指定的值
res = ls[1]print(res)
Output: [4, 5, 6]
res = res[1]print(res)
Output:5
num = 9print(ls[2][2])
Output:[9]
print(id(num), id(ls[2][2][0]), id(ls[2][2]))
Output:
1646292704 1646292704 1902181723080
6.字典
# 列表能存放多个值,但多个值只能通过index区分,但是index没有语义
# 需找即可以存放多个值,切每个值有一个语义描述 => dict类型
# 定义:{ }是用来定义字典的语法,key是用来描述最终要访问的value值的,key对于开发者来说是已知的
# 访问:通过 dic[key]来访问key描述的值
dic = {'key': 'value'}
people = {
'name': 'Liuxx',
'age': 68,
'gender': '哇塞'
}
# 整体访问
print(people) Output:
{'name': 'Liuxx', 'age': 68, 'gender': '哇塞'}
# 访问年龄的值,[将key原样拿下来] => ['age']
print(people['age']) Output:
68
# 字典的嵌套
info = {
'name': 'egon',
'hobbies': ['play', 'sleep'],
'company_info': {
'name': 'Oldboy',
'type': 'education',
'emp_num': 40,
}
}
# 拿到40 | 拿到 'sleep'
res = info['company_info']['emp_num']
print(res)
res = info['hobbies'][1]
print(res) Output:
40
sleep
students=[
{'name':'alex','age':38,'hobbies':['play','sleep']},
{'name':'egon','age':18,'hobbies':['read','sleep']},
{'name':'wupeiqi','age':58,'hobbies':['music','read','sleep']},
]
# 第二个学生的第一个爱好
print(students[1]['hobbies'][0]) Output:
read
PythonStudy——数据类型 Type of data的更多相关文章
- 【12c】扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE
[12c]扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE 在12c中,与早期版本相比,诸如VARCHAR2, NAVARCHAR2以及 RAW这些数据类型的 ...
- The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name
可以强迫部署EntityFramework.SqlServer.dll这个文件到输出目录 找到1个老外的帖子,戳这里(本人测试无效,大家有可能试一下..) 解决方案以下: 在EF的上下文代码CS文件( ...
- Unable to load type System.Data.Entity.DynamicProxiesXXXXXrequired for deserialization.
Memcache实例的Get方法时抛出了异常“Unable to load type System.Data.Entity.DynamicProxies.AdInfoItems_19CD09C8E46 ...
- VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"
错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...
- 服务器返回:type":"Buffer","data":
接口中返回"type":"Buffer","data":[32,232,175,183,233,151,174,229,177,177,23 ...
- MVC中异常: An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll的一种解决办法
今天在调试MVC的例子的时候,总是出错(An exception of type 'System.Data.ProviderIncompatibleException' occurred in Ent ...
- Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' does not have an implementation
一.错误信息 Entity Framework 6.0数据迁移:Add-Migration XXXX 命令发生错误 System.Reflection.TargetInvocationExceptio ...
- PythonStudy——数据类型总结 Data type summary
按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息,可变.集合中的元素必须是可hash的,即不可变的数据类型. 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索 ...
- PythonStudy——数据类型转化 Data type conversion
类型转换 1.数字类型:int() | bool() | float() 2.str与int:int('10') | int('-10') | int('0') | float('-.5') | fl ...
随机推荐
- loadrunner中web_reg_save_param和web_reg_save_param_ex的区别
在使用Loadrunner进行性能测试,编写接口请求脚本时,通过会用到关联函数,而web_reg_save_param和web_reg_save_param_ex的函数有什么区别呢?以下为总结的两点, ...
- CentOS下redis-cli安装
Step1:安装gcc wget等系统lib yum install -y gcc wget Step2:获取redis稳定版并解压 cd /tmp wget http://download.redi ...
- minitab笔记
1.如何用minitab检测一组数据是否服从正态分布 打开Minitab之后点击Stat>Basic Statistics> Normality Test,分析之后若 P value(P值 ...
- Web版记账本开发记录(七)
经过不懈的努力,虽然开发出来的还有瑕疵,但今后我会继续努力的.
- git项目远程地址修改后本地如何处理
今天运维人员为了方便管理,将远程的项目地址给迁移了, 原来是 git@git.lalala.com:yuanlaide/happy.git 变成了 git@git.lalala.com:houlaid ...
- SpringBoot之依赖注入DI
相关注解: @Component @Service @Controller @Repository --------------------------------------------- @Inj ...
- 【洛谷p1605】迷宫
(还记得我昨天大概没人看到的博客(我删辽)吗qwq,2019.4.14下午交的qwq 那篇博客大致内容就是:我提交楼上这道题,交了好久好久好久好久 现在我告诉你,那次评测还N/A着呢qwq) tqlq ...
- 前端布局神器display:flex
2009年,W3C提出了一种新的方案--Flex布局,可以简便.完整.响应式地实现各种页面布局.目前已得到所有现在浏览器的支持. flex浏览器支持 一.Flex布局是什么? Flex是Flexi ...
- 通过cookie记录,设置页面访问的跳转页
通过cookie记录,设置页面访问的跳转页 转载自:http://blog.csdn.net/yixiao_naihe/article/details/26679515. 目的: 1.访问fm.htm ...
- Java反序列化漏洞实现
一.说明 以前去面试被问反序列化的原理只是笼统地答在参数中注入一些代码当其反序列化时被执行,其实“一些代码”是什么代码“反序列化”时为什么就会被执行并不懂:反来在运营商做乙方经常会因为java反反序列 ...