内建函数:
divmod,返回商和余数
模块:
In [17]: from __future__ import division
In [18]: 5/2
Out[18]: 2.5
In [19]: 9/2
Out[19]: 4.5
In [20]: 9.0/2
Out[20]: 4.5
In [21]: 9/2.0
Out[21]: 4.5
得到浮点数的结果
数值类型:
In [1]: 2 ** 31 Out[1]: 2147483648 In [2]: a=99999999999999999999999999999999999999999 In [3]: a Out[3]: 99999999999999999999999999999999999999999L In [4]: type(a) Out[4]: long In [5]: 3/2 Out[5]: 1 In [7]: 3.0/2 Out[7]: 1.5 In [8]: type(3.0/2) Out[8]: float In [9]: a=23j In [10]: type(a) Out[10]: complex In [11]:
字符串:
In [21]: a='abcde' In [22]: a Out[22]: 'abcde' In [23]: a[0] Out[23]: 'a' In [24]: a[4] Out[24]: 'e' In [25]: a[-1] Out[25]: 'e' In [26]: a[0]+[1] In [27]: a[0]+a[1] Out[27]: 'ab' In [28]: a[0:2] Out[28]: 'ab' In [29]: a[:2] Out[29]: 'ab' In [30]: a[1:] Out[30]: 'bcde' In [31]: a[::] Out[31]: 'abcde' In [32]: a[:-1] Out[32]: 'abcd' In [33]: a[::1] Out[33]: 'abcde' In [34]: a[::2] Out[34]: 'ace' In [35]: a[:] Out[35]: 'abcde' In [36]: a[-4:-2] Out[36]: 'bc' In [37]: a[-2:-4:-1] Out[37]: 'dc'
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。