码迷,mamicode.com
首页 > 其他好文 > 详细

内置函数

时间:2019-12-09 21:14:12      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:tab   pip   abc   popen   dev   local   art   oca   pac   

# dir()函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表
# import os
# print(dir(os))
‘‘‘
[‘DirEntry‘, ‘F_OK‘, ‘MutableMapping‘, ‘O_APPEND‘, ‘O_BINARY‘, ‘O_CREAT‘, ‘O_EXCL‘, ‘O_NOINHERIT‘, ‘O_RANDOM‘, ‘O_RDONLY‘, ‘O_RDWR‘, ‘O_SEQUENTIAL‘, ‘O_SHORT_LIVED‘, ‘O_TEMPORARY‘, ‘O_TEXT‘, ‘O_TRUNC‘, ‘O_WRONLY‘, ‘P_DETACH‘, ‘P_NOWAIT‘, ‘P_NOWAITO‘, ‘P_OVERLAY‘, ‘P_WAIT‘, ‘PathLike‘, ‘R_OK‘, ‘SEEK_CUR‘, ‘SEEK_END‘, ‘SEEK_SET‘, ‘TMP_MAX‘, ‘W_OK‘, ‘X_OK‘, ‘_Environ‘, ‘__all__‘, ‘__builtins__‘, ‘__cached__‘, ‘__doc__‘, ‘__file__‘, ‘__loader__‘, ‘__name__‘, ‘__package__‘, ‘__spec__‘, ‘_execvpe‘, ‘_exists‘, ‘_exit‘, ‘_fspath‘, ‘_get_exports_list‘, ‘_putenv‘, ‘_unsetenv‘, ‘_wrap_close‘, ‘abc‘, ‘abort‘, ‘access‘, ‘altsep‘, ‘chdir‘, ‘chmod‘, ‘close‘, ‘closerange‘, ‘cpu_count‘, ‘curdir‘, ‘defpath‘, ‘device_encoding‘, ‘devnull‘, ‘dup‘, ‘dup2‘, ‘environ‘, ‘error‘, ‘execl‘, ‘execle‘, ‘execlp‘, ‘execlpe‘, ‘execv‘, ‘execve‘, ‘execvp‘, ‘execvpe‘, ‘extsep‘, ‘fdopen‘, ‘fsdecode‘, ‘fsencode‘, ‘fspath‘, ‘fstat‘, ‘fsync‘, ‘ftruncate‘, ‘get_exec_path‘, ‘get_handle_inheritable‘, ‘get_inheritable‘, ‘get_terminal_size‘, ‘getcwd‘, ‘getcwdb‘, ‘getenv‘, ‘getlogin‘, ‘getpid‘, ‘getppid‘, ‘isatty‘, ‘kill‘, ‘linesep‘, ‘link‘, ‘listdir‘, ‘lseek‘, ‘lstat‘, ‘makedirs‘, ‘mkdir‘, ‘name‘, ‘open‘, ‘pardir‘, ‘path‘, ‘pathsep‘, ‘pipe‘, ‘popen‘, ‘putenv‘, ‘read‘, ‘readlink‘, ‘remove‘, ‘removedirs‘, ‘rename‘, ‘renames‘, ‘replace‘, ‘rmdir‘, ‘scandir‘, ‘sep‘, ‘set_handle_inheritable‘, ‘set_inheritable‘, ‘spawnl‘, ‘spawnle‘, ‘spawnv‘, ‘spawnve‘, ‘st‘, ‘startfile‘, ‘stat‘, ‘stat_result‘, ‘statvfs_result‘, ‘strerror‘, ‘supports_bytes_environ‘, ‘supports_dir_fd‘, ‘supports_effective_ids‘, ‘supports_fd‘, ‘supports_follow_symlinks‘, ‘symlink‘, ‘sys‘, ‘system‘, ‘terminal_size‘, ‘times‘, ‘times_result‘, ‘truncate‘, ‘umask‘, ‘uname_result‘, ‘unlink‘, ‘urandom‘, ‘utime‘, ‘waitpid‘, ‘walk‘, ‘write‘]
‘‘‘
# divmod()返回商和余数
# print(divmod(10,3)) # (3, 1)

# enumerate() # 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。
# l=[‘a‘,‘b‘,‘c‘]
# for i in l:
# print(l.index(i),i)
‘‘‘
0 a
1 b
2 c
‘‘‘
# for item in enumerate(l):
# print(item)
‘‘‘
(0, ‘a‘)
(1, ‘b‘)
(2, ‘c‘)
‘‘‘
# for i,v in enumerate(l):
# print(i,v)
‘‘‘
0 a
1 b
2 c
‘‘‘
# eval()
# eval("print(‘xxxxx‘)") # xxxxx
# exec("print(‘xxxxx‘)") # xxxxx
# res=eval(‘[1,2,3]‘)
# print(res,type(res)) # [1, 2, 3] <class ‘list‘>
# res=exec(‘[1,2,3]‘)
# print(res,type(res)) # None <class ‘NoneType‘>

# frozenset()
# s=set({1,2,3})
# s.add(4)
# print(s) # {1, 2, 3, 4}
# s=frozenset({1,2,3})# 不可变集合

# hash() 不可变类型可以hash
# print(hash(‘xxx‘)) # 3130826652003433760

# pow() 取余
# res=pow(10,3,3)
# print(res) # 1

# reversed() 单纯反转
# l=[1,2,3]
# print(list(reversed(l))) # [3, 2, 1]

# round() 四舍五入
# print(round(3.5)) # 4

# slice() 切片
# s=slice(1,7,2)
# l=[1,2,3,4,5,6,7]
# print(l[s]) # [2, 4, 6]

# vars()
# print(vars() is locals()) # True

内置函数

标签:tab   pip   abc   popen   dev   local   art   oca   pac   

原文地址:https://www.cnblogs.com/0B0S/p/12013257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!