python 数据类型
来源:互联网 发布:如何查看手机网络制式 编辑:程序博客网 时间:2024/06/05 02:54
1.python是什么类型的语言
python 是脚本语言
2.python 数据类型
python 数据类型包括整型、浮点型、字符串、布尔类型
3.python变量
1.使用变量前必须先赋值
2.变量名包括字母、数字、下划线,但不能以数字开头
3.字母区分大小写
4.整型
Python可以处理任意大小的整数,在整型操作中**表示平方,如:
5**2 等于5的平方 为258**3 等于8的3次方 为512
5.浮点数
在浮点数中处理很大或者很小的浮点数用科学计数法表示,如:2e2
2e2 表示为2 * 10的平方5.0e3 表示为5.0 * 10的三次方
6.布尔类型
布尔类型中True 或者False首字母都为大写,True == 1,False == 0,如:True + False == 1 + 0 = 1
7.字符串
1.字符串出现”中出现‘需要,如str = ‘xi’an’
字符串的单引号”可用”“代替
字符串中的’进行转义,如:\’
2.字符串中出现’\n’转义符,如:
path = 'C:\now\file\python'print(path)
path中有 \n 和 \f 转义符,可在字符串前加 ’ r ’ 变为原始字符串,如:
path = r'C:\now\file\python'print(path)
8.类型转换
整型 < - - - - > 字符串
a = 5 为整型 ---> 转字符串 为 str(a) 结果为'5'b = '10' 为字符串 ---> 转整型 为 int(b) 结果为 10
整型 < - - - - > 浮点数
a = 5 为整型 ---> 转浮点数 为 float(a) 结果为5.0b = 8.0 为浮点数 ---> 转整型 为 int(b) 结果为 8
字符串 < - - - - > 浮点数
a = '5' 为字符串 ---> 转浮点数 为 float(a) 结果为5.0b = 8.0 为浮点数 ---> 转字符串 为 str(b) 结果为 '8.0'
布尔类型 - - - - > 浮点数、整型
a = True 布尔类型 ---> 转浮点数、整型,因为 True == 1,所以float(a) == 1.0; int(a) == 1
9.获得类型的信息
isinstance() 如 a = 5, b = 8.0, c = ‘zxy’, d = True
isinstance(a,int) ---> Trueisinstance(b,float) ---> Trueisinstance(c,str) ---> Trueisinstance(d,bool) ---> True
10.算术操作符
+ , - , * , / , % , ** , //
//表示地板除、向下取整数,如:5//2 = 2, 14//5 = 2
11.逻辑运算符
not , and , or
not True - - -> False
True and False - - - > False
True or False - - - > True
阅读全文
0 0
- Python 数据类型
- python--数据类型
- python 数据类型
- python数据类型
- Python---数据类型
- python数据类型
- python数据类型
- [python] 数据类型
- python数据类型
- python 数据类型
- Python数据类型
- Python数据类型
- Python-数据类型
- Python数据类型
- Python数据类型
- python数据类型
- python 数据类型
- python数据类型
- VS2015 OpenGL开发环境简单配置 glfw + glad
- go语言实现发送邮件带附件
- URAL
- day24笔记
- 运算符之:2、算术运算符(7个)
- python 数据类型
- mysql 登录问题
- day25笔记
- Storm之——流组件简单串行编程实践
- day26笔记
- 从jsp页面发送ajax请求,servlet接受参数并返回json数据
- 算法分析与设计第九周
- day27笔记
- 深入理解JavaScript编程中的同步与异步机制