数据类型:信息存在的状态
为什么要来描述事物的具体状态:不同的事物需要不同的状态加以描述可以达到描述的最优化

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的更多相关文章

  1. 【12c】扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE

    [12c]扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE 在12c中,与早期版本相比,诸如VARCHAR2, NAVARCHAR2以及 RAW这些数据类型的 ...

  2. 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文件( ...

  3. Unable to load type System.Data.Entity.DynamicProxiesXXXXXrequired for deserialization.

    Memcache实例的Get方法时抛出了异常“Unable to load type System.Data.Entity.DynamicProxies.AdInfoItems_19CD09C8E46 ...

  4. VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"

    错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...

  5. 服务器返回:type":"Buffer","data":

    接口中返回"type":"Buffer","data":[32,232,175,183,233,151,174,229,177,177,23 ...

  6. MVC中异常: An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll的一种解决办法

    今天在调试MVC的例子的时候,总是出错(An exception of type 'System.Data.ProviderIncompatibleException' occurred in Ent ...

  7. Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' does not have an implementation

    一.错误信息 Entity Framework 6.0数据迁移:Add-Migration XXXX 命令发生错误 System.Reflection.TargetInvocationExceptio ...

  8. PythonStudy——数据类型总结 Data type summary

    按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息,可变.集合中的元素必须是可hash的,即不可变的数据类型. 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索 ...

  9. PythonStudy——数据类型转化 Data type conversion

    类型转换 1.数字类型:int() | bool() | float() 2.str与int:int('10') | int('-10') | int('0') | float('-.5') | fl ...

随机推荐

  1. 3、基于多播、安全认证的corosync集群(VIP、Httpd、Filesystem)

    Messaging Layer --> CRM --> RA systemd:/usr/lib/systemd/system     systemd有一个特性,即便一个服务开机启动,但是在 ...

  2. zabbix-3.4.14源码安装

    此次介绍一下,zabbix的源码安装,因为zabbix的依赖很多,所以源码安装有很多依赖需要安装 首先,下载zabbix源码包 wget https://nchc.dl.sourceforge.net ...

  3. Pandas 基础(5) - 处理缺失的数据

    首先, 读入一个 csv 文件: import pandas as pd df = pd.read_csv('/Users/rachel/Sites/pandas/py/pandas/5_handli ...

  4. 北京动点飞扬软件招募【Android全职工程师】

    要求: 1 至少半年2年以上android开发经验,能力第一,学历不限 2 至少5个以上正规app开发经验 3 项目周期12个月左右,要求一周内到岗 4 有意向者简历请发邮箱372900288@qq. ...

  5. Fabric 1.0交易流程

    这篇文章详细介绍fabric的交易流程,以图片加文字的形式呈现. Fabric 1.0交易流程 fabric中的所有交易都是通过chaincode执行 1.应用程序客户端通过SDK调用证书服务(CA) ...

  6. 学习GT一书前九章的体会

    学习Gilbarg和Trudinger一书前九章的体会 本书第二章,调和函数的基本性质进行展示.特别的对比较定理有深刻的阐述以及Perron方法的基本说明,并对Wiener准则作了简要说明. 第三章的 ...

  7. 百度echarts 3.0版本和2.0版本的兼容问题

    前一段时间,项目中要用到统计图表,之前也用过jqplot的图表插件,这次开发的内容中基于地图的展示还很多,所以后来选择了百度的echarts插件(echarts.baidu.com).刚开始用的时候, ...

  8. node设置跨域

    开发过程中在build/dev-server.js配置相关代码以跨域 app.use('/api',proxyMiddleware({ target:'http://m.maizuo.com/v4', ...

  9. elastic search 重要的系统配置

    文章翻译自 https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html 1.文件描述符 ...

  10. VSTO:使用C#开发Excel、Word【12】

    Excel对象模型中的事件了解excel对象模型中的事件至关重要,因为这通常是代码运行的主要方式.本章将检查Excel对象模型中的所有事件,引发事件以及可能与这些事件关联的代码类型. Excel对象模 ...