abs
print(abs(10))
print(abs(-10))
print(abs(-1.1))
10
10
1.1
abs(0.00000001 - 0) < 1e-6
True
bool
print(bool(0))
print(bool(1))
False
True
print(bool(None))
print(bool(''))
print(bool([]))
print(bool({}))
False
False
False
False
print(bool(' '))
True
dir
显示可调用的函数
dir([])
['__add__',
'__class__',
'__contains__',
'__delattr__',
'__delitem__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__gt__',
'__hash__',
'__iadd__',
'__imul__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__rmul__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__',
'append',
'clear',
'copy',
'count',
'extend',
'index',
'insert',
'pop',
'remove',
'reverse',
'sort']
用help显示某个函数的简短描述
help([].append)
Help on built-in function append:
append(...) method of builtins.list instance
L.append(object) -> None -- append object to end
class A():
"""
A is just a test class
"""
def __init__(self):
pass
def printA(self):
pass
def Hello(self):
pass
a = A()
dir(A)
['Hello',
'__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'printA']
help(A)
Help on class A in module __main__:
class A(builtins.object)
| A is just a test class
|
| Methods defined here:
|
| Hello(self)
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| printA(self)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
A.__doc__
'\n A is just a test class\n '
sum
sum([1,2,3,4,5])
15
eval exec
eval('10**2')
100
my_small_program = '''
for i in range(10):
print(i, end = '')
'''
exec(my_small_program)
0123456789