函数:
http://docs.python.org/2/library/functions.html#abs
# -*- coding: UTF-8 -*-
help(abs)
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/t1.py
Help on built-in function abs in module __builtin__:
abs(...)
abs(number) -> number
Return the absolute value of the argument.
# -*- coding: UTF-8 -*-
print abs(-20)
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/t1.py
20
# -*- coding: UTF-8 -*-
print abs(-20,1)
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/t1.py
Traceback (most recent call last):
File "C:/Users/TLCB/PycharmProjects/untitled/t1.py", line 2, in <module>
print abs(-20,1)
TypeError: abs() takes exactly one argument (2 given)
Process finished with exit code 1
# -*- coding: UTF-8 -*-
print abs('-20')
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/t1.py
Traceback (most recent call last):
File "C:/Users/TLCB/PycharmProjects/untitled/t1.py", line 2, in <module>
print abs('-20')
TypeError: bad operand type for abs(): 'str'
数据类型转换:
>>> '123'
'123'
>>> int('123')
123
>>>