复习内置函数

# 复习内置函数
print
input
len
type
open

tuple
list

dir
id
help

range
next
iter

eval
exec
# 执行字符串中的文字
# 不同:exec没有返回值,切断返回值,中间流程
# eval 不安全,适用有返回值的简单计算
# 特别:字符串中文字有交互如input,使用compile(code,single)
compile #一次编译,终生执行
code = 'print(123)'
comp1 = compile(code,exec)
exec(comp1)

callable # 判断一个变量是不是函数,这个变量后面有没有括号
print(callable(print)) # True
a = 1
print(callable(a)) # False

# 文件操作
writable # 可不可写
readable #可不可读

hash # 可不可哈希,能哈希显示哈希结果

print('XXX',end='',file='X') # X如果是文件句柄的话是重定向到文件
动态打印:
import time
for i in range(0,101,2):
    time.sleep(0.1)
    char_num = i//2

# progress Bar API打印精度条

abs #绝对值
divmod #除余方法
divmod(3,2) #1(除法),2(剩下余数)
round # 小数精确
round(3.141592,3) #四舍五入
pow #幂运算
pow(2,3)
a = [1, 2, 3, 4]
print(a.reverse())
b = reversed(a)
print(b)
l = (1,2,24,215,567)
sli = slice(1,5,2)
print(l[sli])
print(l[1:5:2])
print(repr('1'))
print(repr(1))
# repr把内容带着类型输出
原文地址:https://www.cnblogs.com/shuoran/p/11661539.html