当前位置: 移动技术网 > IT编程>脚本编程>Python > Python 学习笔记(三)数字

Python 学习笔记(三)数字

2018年03月10日  | 移动技术网IT编程  | 我要评论

少年阿宾sodu,变身辣妹下载,福陵山取经坐标

Python 数字

  int 整型  是正或负整数  2

  long 长整型  整数最后是一个大写或小写的L   2L

  float  浮点型 由整数部分和小数部分组成   2.0

  complex 复数 

 

小结 

  1、用内建函数 type 可查看数据类型

1 >>> type(2)
2 <type 'int'>
3 >>> type(2L)
4 <type 'long'>
5 >>> type(2.0)
6 <type 'float'>
7

  2、使用dir(__builtins__)查看更多的内建函数 (builtins前后有两个下划线)

1 >>> dir(__builtins__)
2 ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']

  3、使用help()   help(type)查看type内建函数的具体内容

 1 >>> help(type)
 2 Help on class type in module __builtin__:
 3 
 4 class type(object)
 5  |  type(object) -> the object's type
 6  |  type(name, bases, dict) -> a new type
 7  |
 8  |  Methods defined here:
 9  |
10  |  __call__(...)
11  |      x.__call__(...) <==> x(...)
12  |
13  |  __delattr__(...)
14  |      x.__delattr__('name') <==> del x.name
15  |
16  |  __eq__(...)
17  |      x.__eq__(y) <==> x==y
18  |
19  |  __ge__(...)
20  |      x.__ge__(y) <==> x>=y
21  |
22  |  __getattribute__(...)
23  |      x.__getattribute__('name') <==> x.name
24  |
25  |  __gt__(...)
26  |      x.__gt__(y) <==> x>y
27  |
28  |  __hash__(...)
29  |      x.__hash__() <==> hash(x)
30  |
31  |  __init__(...)
32  |      x.__init__(...) initializes x; see help(type(x)) for signature
33  |
34  |  __instancecheck__(...)
35  |      __instancecheck__() -> bool
36  |      check if an object is an instance
37  |
38  |  __le__(...)
39  |      x.__le__(y) <==> x<=y

  4、id() 内建函数查看对象的id编号   

    判断是不是同一对象需要判断id返回的编号是否相同

1 >>> id(2)
2 42753392L
3 >>> id(3)
4 42753368L

 

Python 变量

 什么是变量

  变量是存储在内存中的值,创建一个变量意味着在内存中开辟一个空间。

  变量无类型,对象有类型

  变量命名  a  a_b  大写T_A 为全局变量 

1 、简单的运算

 1 >>> a =10
 2 >>> b = 2
 3 >>> c = 4
 4 >>> a / b
 5 5
 6 >>> a / b + c
 7 9
 8 >>> a * b
 9 20

2、大整数相乘问题

  Python 将自动把数据转换为长整数

1 >>> 1233333333333322222222222*6666666666666666666
2 8222222222222148147325924444444451851851852L

 

3、运算符号

运算符描述实例
+ 加 - 两个对象相加 a + b 输出结果 30
- 减 - 得到负数或是一个数减去另一个数 a - b 输出结果 -10
* 乘 - 两个数相乘或是返回一个被重复若干次的字符串 a * b 输出结果 200
/ 除 - x除以y b / a 输出结果 2
% 取模 - 返回除法的余数 b % a 输出结果 0
** 幂 - 返回x的y次幂 a**b 为10的20次方, 输出结果 100000000000000000000
// 取整除 - 返回商的整数部分 9//2 输出结果 4 , 9.0//2.0 输出结果 4.0

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网