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 ...
随机推荐
- pixi.js(入门)
1.关于 一个关于HTML5 2D渲染引擎,它的独特之处在于其拥有了canvas回调功能的WebGL,速度快,能够兼容所有设备,简单得说也就是跨平台了,我用的开发工具是WebStorm 2.参考API ...
- Redis出现的问题
1):Could not connect to Redis at 127.0.0.1:6379: Connection refused 分析: 1-1:虚拟机中的 6379 端口可能没有开启 查看虚拟 ...
- xss攻击(转)
什么是 XSS Cross-Site Scripting(跨站脚本攻击)简称 XSS,是一种代码注入攻击.攻击者通过在目标网站上注入恶意脚本,使之在用户的浏览器上运行.利用这些恶意脚本,攻击者可获取用 ...
- Java版 人脸识别SDK dem
虹软人脸识别SDK之Java版,支持SDK 1.1+,以及2.0版本,滴滴,抓紧上车! 前言由于业务需求,最近跟人脸识别杠上了,本以为虹软提供的SDK是那种面向开发语言的,结果是一堆dll······ ...
- stylus笔记(三)
1.@import 导入 Stylus支持字面@import CSS, 也支持其他Stylus样式的动态导入. 任何.css扩展的文件名将作为字面量.例如: @import "reset.c ...
- 三款免费实用的文件夹同步/备份软件推荐 (SyncToy/FreeFileSync/Compare Advance)
三款免费实用的本地文件夹同步/备份软件推荐 (SyncToy/FreeFileSync/Compare Advance) Microsoft SyncToy SyncToy 是由 微软 推出的一款免费 ...
- 【JS】【6】判断一个元素是否在数组中
摘要: 有三种方式: 1,jquery的inArray方法 2,数组的indexOf方法 3,普通的for循环方法 正文: 1,jquery的inArray方法 /** * @param {Objec ...
- React文档(十六)refs和DOM
Refs 提供了一种方式,用于访问在 render 方法中创建的 DOM 节点或 React 元素. 在标准的React数据流中,props是使得父组件和子组件之间交互的唯一方式.你通过props重新 ...
- DFS 之 全排列
题目描述输出自然数1到n所有不重复的排列,即n的全排列,要求所产生的任一数字序列中不允许出现重复的数字. 我们可以模拟出n个盒子和n张卡片,我们需要将n张卡片分别放到n个盒子里,且每个盒子只能放1张卡 ...
- CSS中的伪类与伪元素
在前端开发中,大家或多或少的有接触过CSS伪类和伪元素,使用伪元素的时候,总感觉和伪类很相似,但又不能详细的说出两者的区别和联系,那么两者到底有什么区别和联系呢? 在 W3C 中定义: 伪类:用于向某 ...