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 ...
随机推荐
- jQuery学习笔记(一)
jQuery 事件 - ready() 方法 实例 在文档加载后激活函数(): $(document).ready(function(){ $(".btn1").click(fun ...
- 获取添加数据的自增ID
$id= DB::select("select auto_increment from information_schema.`TABLES` where table_name='stude ...
- webpack4入门
前提 已安装node(版本号>4.0,已自带NPM) mac机器 有一个空目录 无webpack.config.js配置打包 快速构建package.json文件. npm init -y 安装 ...
- Linux ssh下实现免密码登录
1.Linux 生成密钥 ssh-keygen -t rsa 进入“.ssh”会生成以下几个文件 id_rsa : 生成的私钥文件 id_rsa.pub : 生成的公钥文件 know_hosts : ...
- HDU 2612 (2次BFS,有点小细节)
Problem Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. L ...
- [IDE - Eclipse] JSP报错:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
是因为Eclipse的Web项目不自动引入相关jar包. Right Click on the Project ❯ Properties ❯ Project Facets. You would be ...
- Practical Node.js (2018版) 14章, async code in Node
Asynchronous Code in Node 历史上,Node开发者只能用回调和事件emitters. 现在可以使用一些异步的语法: async module Promises Async/aw ...
- CRM INBOX 结果增强功能
前段时间接到的需求:INBOX(ICCMP_INBOX)查询结果,多选后弹出选择用户的框,选择用户,带入到单据的PARTNER FUNC的工程师中,并修改单据状态. 其实标准的INBOX的Compon ...
- element-ui <el-input> 注册blur事件
<template> <div class="demo"> <el-input placeholder="注册blur事件" v- ...
- The C compiler identification is unknown解决办法
环境:VS2015,CMake3.12.0. 问题一: 解决办法:下载并安装Windows SDK version 8.1. 问题二: 解决办法:这个问题百度了半天也没找到合适的办法,好多博客都是复制 ...