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

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. 算法笔记--极大极小搜索及alpha-beta剪枝

    参考1:https://www.zhihu.com/question/27221568 参考2:https://blog.csdn.net/hzk_cpp/article/details/792757 ...

  2. 『Python』多进程处理

    尝试学习python的多进程模组,对比多线程,大概的区别在: 1.多进程的处理速度更快 2.多进程的各个子进程之间交换数据很不方便 多进程调用方式 进程基本使用multicore() 进程池优化进程的 ...

  3. linux系统下如何挂载NTFS移动硬盘

    前言 数据迁移是我们经常会遇到的,有时候做大数据量迁移时,为了快速迁移大数据,有可能在Linux服务器上临时挂载NTFS格式的移动硬盘, 一般情况下,Linux是识别不了NTFS格式移动硬盘的(需要重 ...

  4. 3、简单了解Angular应用的启动过程

    首先,了解一下目录结构: 然后,简明扼要的说一下应用的启动过程: 1.首先找到main.ts(模块启动入口),main.ts去找到app中的根模块app.module.ts 2.根模块app.modu ...

  5. 线程基础:多任务处理——MESI协议以及带来的问题:伪共享

    1.概述 本文和后续文章将着眼CPU的工作原理阐述伪共享的解决方法和volatile关键字的应用. 2.复习CPU工作原理2.1.CPU工作原理要清楚理解本文后续内容,就需要首先重新概述一下JVM的内 ...

  6. spring boot 常见的配置问题

    最近在自学spring boot ,新手教程网上很多,这里主要记录下配置过程中的一些疑难杂症.这些记录都是针对以下配置生成的项目 1.该项目一定要用jdk1.8 2.application.prope ...

  7. 前端开发【第一篇: HTML】

    HTML初识  1.什么是HTML? HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).  2.网页的组成 我们平时 ...

  8. 字符串format拼接格式化

    # ###字符串的格式化 format"""(1)顺序传参(2)索引传参(3)关键字传参(4)容器类型传参(列表和元组) {} 相当于占位符""&qu ...

  9. TensorFlow 神经网络相关函数

    TensorFlow 激活函数 激活操作提供用于神经网络的不同类型的非线性.这些包括平滑的非线性(sigmoid,tanh,elu,softplus,和softsign),连续的,但不是到处可微函数( ...

  10. 剑指Offer 17. 树的子结构 (二叉树)

    题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 题目地址 https://www.nowcoder.com/practice/6e196c44c7 ...