数据类型

1.核心数据类型
*数字

int | long | float | complax  | bool

*字符

str | unicode

*列表

list

*字典

dict

*元组

tuple

*文件

file

*其它类型

set (集合) | frozenset | 类类型 |None

*其它文件工具

pipies  | fifos | sockets

2.类型转换

str() | repr() | format()  将非字符型数据转化成字符
int():转化为整数
float():
list(s): 将字符串 s 转化为列表
tuple(s): 将字符串 s 转化为列表
set(s): 将字符串 s 转化为集合
frozenset(s): 将字符串 s 转化成为不可变集合
dict(d): 创建字典(d:k-v键值对的元组序列)

chr(x): 将整数转化为字符串
ord(x): 将字符转化为整数值
hex(x):将字符串转化成十六进制字符串
bin(x):将字符串转化成二进制字符串
oct(x): 

3.数字类型

math 库


----------

In [82]: import math

In [83]: math.
math.acos       math.cos        math.factorial  math.ldexp      math.sin
math.acosh      math.cosh       math.floor      math.lgamma     math.sinh
math.asin       math.degrees    math.fmod       math.log        math.sqrt
math.asinh      math.e          math.frexp      math.log10      math.tan
math.atan       math.erf        math.fsum       math.log1p      math.tanh
math.atan2      math.erfc       math.gamma      math.modf       math.trunc
math.atanh      math.exp        math.hypot      math.pi         
math.ceil       math.expm1      math.isinf      math.pow        
math.copysign   math.fabs       math.isnan      math.radians    

----------


Python的数字字面量:
布尔型 | 整数 | 浮点数 | 复数

>>移位  箭头朝哪边向哪边移动
In [70]: num7 = 2   | 10

In [71]: num7 << 3   |10000
Out[71]: 16

& 按位与
| 按位或
In [76]: True & False
Out[76]: False

In [77]: 1&0
Out[77]: 0

In [78]: 255&101
Out[78]: 101

In [80]: 255 | 101
Out[80]: 255

4.序列类型

“`
*字符类型
字符串字面量:把文本放入单引号”|双引号”“|三引号当中(可实现跨行定义)原样输出

如果要保存为 unicode 编码格式,需要在字符串前面加上 u
In [83]: str1 = u”hello nihao”
In [84]: type(str1)
Out[84]: unicode

*文档字串
模块|类|函数的第一句是一个字符的话(注:只能是第一行,否则doc属性引用不出来),该字符串就成为文档字串,可以使用doc属性引用,但是需要注意的是,文档字串在代码段中要与其它语句的缩进保持一致


In [85]: def printName():
….: “test function”
….: print “Ni hao today!”
….:

In [86]: printName()
Ni hao today!

In [87]: printName().doc #加()是引用函数本身
Ni hao today!

In [88]: printName.doc #不加()是引用doc属性
Out[88]: ‘test function’

In [89]:


5In [4]: z = 1.234-4 +5.6e+89j

In [5]: z.real #获取复数实部
Out[5]: -2.766

In [6]: z.imag #获取复数虚部
Out[6]: 5.6e+89“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值