一、核心数据类型:

  • 数字(int整型、float浮点型、complex复数、bool布尔型)
  • 字符串 str
  • 列表(List)
  • 元组(Tuple)
  • 字典(Dictionary)
  • 集合()

二、可变数据类型  和  不可变数据类型

可变数据类型(不可哈希):列表、字典、集合

  • 可变有序:列表(通过下标可以找到)
  • 可变无序:字典、集合

不可变数据类型(可哈希):字符串、元组、固定集合、bool、int

  • 不可变有序:字符串、元组(通过下标可以找到)
  • 不可变无序:固定集合

三、数据类型之 None 详解

与C不同,在python中是没有NULL,但存在相近意义的None。

print type(None)     # <type 'NoneType'>
print dir(None) # ['__class__', '__doc__', '__init__', '__new__', '__repr__', '__setattr__', '__str__']

None是没有像len,size等属性的,要判断一个变量是否为None,直接使用

print None == 0         # False
print None == ' ' # False
print None == None # True
print None == False # False a = None
if a:
print "a is True" # 不打印
if a is None:
print "a is None" # 打印
if a == None:
print "a == None" # 打印

四、is 和 == 的区别

https://www.cnblogs.com/mika-blogs/p/10981239.html

数字

整数,浮点型数、字符串互相转换

# str(num) 将整型、浮点型转换成 字符串。
num1 = 66
num2 = 66.88
str1 = str(num1)
str2 = str(num2) # int(str) 函数将 符合整数的规范的字符串转换成 int 型。
str1 = '66'
num1 = int(str1) # float(str) 函数将 符合浮点型的规范的字符串转换成 float 型。
str2 = '66.88'
num2 = float(str2)

浮点数转换整数

from math import *

print int(3.22)         # 3   <type 'int'>
print int(3.66) # 3
print int(-3.22) # -3
print int(-3.66) # -3 print floor(3.22) # 3.0 <type 'float'>
print floor(3.66) # 3.0
print floor(-3.22) # -4.0
print floor(-3.66) # -4.0 print round(3.22) # 3.0 <type 'float'>
print round(3.66) # 4.0
print round(-3.22) # -3.0
print round(-3.66) # -4.0

bool布尔型

列表

创建列表

L = []             # 创建空列表的字面值:
L = [1, 2, 3] # 创建非空列表的字面值

列表的构造函数(括号里的是可迭代对象)

list()              # 生成一个空的列表,等同于[]
list(iterable) # 用可迭代对象创建一个列表 arr1 = list("hello")
arr2 = list(range(1,10,2))
print arr1, arr2 # ['h', 'e', 'l', 'l', 'o'] [1, 3, 5, 7, 9]

  

最新文章

  1. ASP.NET Core 中文文档 第四章 MVC(01)ASP.NET Core MVC 概览
  2. Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
  3. python——进程基础
  4. JS高级程序设计2nd部分知识要点2
  5. cisco 路由配置
  6. jquery 属性与css操作
  7. 《python基础教程》笔记之 字典
  8. HttpServletRequest 报错 myeclipese支持tomcat
  9. libvirt命令行文档
  10. Mybatis拦截器实现分页
  11. 【Harmony】概述
  12. 对于JSONObject,我只是临时抱佛脚
  13. QT 操作 excel 教程
  14. MyBatis笔记(一) 最简单的select
  15. python学习笔记(10)--组合数据类型(字典类型)
  16. Turbine——Hystrix集群监控
  17. CentOS乱码解决方法
  18. 终极解决方案:org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
  19. Java获取系统时间的四种方法
  20. Umbraco中使用Related Links显示内部链接和外部链接

热门文章

  1. Android App图片资源文件压缩利器McImage
  2. oracle12.2RAC之OGG安装配置(二)
  3. Centos7 下安装python3及卸载
  4. 微信小程序如何做金额输入限制
  5. 渗透测试学习 二十九、kali安装,信息搜集,服务器扫描
  6. Druid-代码段-1-1
  7. LeetCode解题笔记 - 4. Median of Two Sorted Arrays
  8. 【oracle】查看表空间对应文件所在位置
  9. shell基础概念, if+命令, shell中引用python, shell脚本的几种执行方式
  10. js scroll事件