标签:最好 eal image 复数 false rac view enum png
python3.6的数据类型之int类型:
python每个版本的各种数据类型的属性不太一样,针对所使用的具体的版本,最好用dir()查看一下该版本下的各种数据类型的属性有哪些。
int类型:
Jupyter QtConsole 4.2.1
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython‘s features.
%quickref -> Quick reference.
help -> Python‘s own help system.
object? -> Details about ‘object‘, use ‘object??‘ for extra details.
a=9 dir(a) Out[2]: [‘__abs__‘, #a.__abs__()求a的绝对值 ‘__add__‘, #a.__add__(2) a+2 ‘__and__‘, #与C语言中的按位与一样,a.__and__(30) Out[10]: 8 先转化为二进制,再按比特位做与运算得到的结果
‘__bool__‘, #a.__bool__() 零为false,非零为True ‘__ceil__‘, #貌似没什么意义,a.__ceil__() 大于或等于该整数的最小的整数是它自身 ‘__class__‘, # a.__class__() 是0,对于float类型的数为0.0 ‘__delattr__‘, ‘__dir__‘, ‘__divmod__‘, ‘__doc__‘, ‘__eq__‘, ‘__float__‘, ‘__floor__‘, ‘__floordiv__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getnewargs__‘, ‘__gt__‘, ‘__hash__‘, ‘__index__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__int__‘, ‘__invert__‘, ‘__le__‘, ‘__lshift__‘, ‘__lt__‘, ‘__mod__‘, ‘__mul__‘, ‘__ne__‘, ‘__neg__‘, ‘__new__‘, ‘__or__‘, ‘__pos__‘, ‘__pow__‘, ‘__radd__‘, ‘__rand__‘, ‘__rdivmod__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__rfloordiv__‘, ‘__rlshift__‘, ‘__rmod__‘, ‘__rmul__‘, ‘__ror__‘, ‘__round__‘, ‘__rpow__‘, ‘__rrshift__‘, ‘__rshift__‘, ‘__rsub__‘, ‘__rtruediv__‘, ‘__rxor__‘, ‘__setattr__‘, ‘__sizeof__‘,##a=11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111随着整数a的位数的变化,a.__sizeof__()的大小在变化 ‘__str__‘, ‘__sub__‘, ##a.__sub__(d) 即为 a-d ‘__subclasshook__‘, ‘__truediv__‘, ‘__trunc__‘, ‘__xor__‘, ‘bit_length‘, #转化为二进制后的位数a.bit_length() ‘conjugate‘, ##求该数的共轭复数 c=4+3j c.conjugate() (4-3j) ‘denominator‘, ###a.denominator返回1 a的分母是1 注意不用圆括号 ‘from_bytes‘, ‘imag‘, ##a.imag 是0,float类型的返回0.0 ‘numerator‘, ##a.numerator返回其自身的值9 ‘real‘, ##a.real返回9 ‘to_bytes‘] ###a.to_bytes(10,"little") 返回:b‘\t\x00\x00\x00\x00\x00\x00\x00\x00\x00‘不知道是什么意思 a.to_bytes(3,"big")
d=["a","b","c","d"]
for k,v in enumerate(d,1):
print(k,v)
1 a
2 b
3 c
4 d
十进制转化为2进制、8进制、16进制
a=123
bin(a)
Out[130]: ‘0b1111011‘
hex(a)
Out[131]: ‘0x7b‘
oct(a)
Out[132]: ‘0o173‘
二进制、8进制、16进制字符串转化为10进制整数
a=123
b=bin(a)
type(b)
Out[144]: str
int(b,2)
Out[145]: 123
bin(a)
Out[146]: ‘0b1111011‘
a1=int(b,2)
type(a1)
Out[148]: int
标签:最好 eal image 复数 false rac view enum png
原文地址:http://www.cnblogs.com/zengqingfu1442/p/7043925.html