python_内置函数1_42

内置函数



内置函数大全:

  Built-in Functions  
abs() dict() help() min() setattr()
all() dir() hex() next() slice()
any() divmod() id() object() sorted()
ascii() enumerate() input() oct() staticmethod()
bin() eval() int() open() str()
bool() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()  
delattr() hash() memoryview() set()  



# print()
# input()
# len()
# type()
# open()
# tuple()
# list()
# int()
# bool()
# set()
# dir()
# id()
# str()
# print(locals())  #返回本地作用域中的所有名字
# print(globals()) #返回全局作用域中的所有名字
# global 变量
# nonlocal 变量

#迭代器.__next__() 等价于 # next(迭代器)
# def next(迭代器):
# 迭代器.__next__() # next() 等价于执行了这个方法

# 迭代器 = iter(可迭代的) #得到迭代器
# 迭代器 = 可迭代的.__iter__() #得到迭代器

# range(10)
# range(1,11)
# range(1,11,2)
# print('__next__' in dir(range(1,11,2))) #range(1,11,2)不是一个迭代器
# iter(range(1,11,2)) #是一个迭代器

# dir 查看一个变量拥有的方法
# print(dir([]))
# print(dir(1))

# help
# help(str)

# 变量
# print(callable(print))
# a = 1
# print(callable(a))
# print(callable(globals))
# def func():pass
# print(callable(func)) # 在后面加上()能被调用的返回 True
# import time
# print(time.time())

# time = __import__('time')
# print(time.time())

# 某个方法属于某个数据类型的变量,就用.调用
# 如果某个方法不依赖于任何数据类型,就直接调用 —— 内置函数 和 自定义函数

# f = open('1.复习.py', encoding='utf-8')
# print(f.read())
# print(f.writable()) #判断文件能不能写
# print(f.readable()) #判断文件能不能读

内存相关的:
 
#id #内存地址

#hash - 对于相同可hash数据的hash值在一次程序的执行过程中总是不变的
# - 字典的寻址方式
# print(hash(12345))
# print(hash('hsgda不想你走,nklgkds'))
# print(hash(('1','aaa')))
# print(hash([])) #不可哈希


字典的寻址方式: key必须是可哈希
  字典的寻址方式快



# ret = input('提示 : ')
# print(ret)
# print('我们的祖国是花园',end='')  #指定输出的结束符  (print默认换行)
# print('我们的祖国是花园',end='')
# print(1,2,3,4,5,sep='|') #指定输出多个值之间的分隔符


# f = open('file','w')
# print('aaaa',file=f) #默认打印到屏幕 file指定打印的文件
# f.close()

f = open('tmp_file','w')
print(123,456,sep=',',file = f,flush=True)



打印进度条:
import time
for i in range(0,101,2):
     time.sleep(0.1)
     char_num = i//2  #打印多少个'*'
per_str = '
%s%% : %s
' % (i, '*' * char_num)  if i == 100 else '
%s%% : %s' % (i,'*'*char_num) print(per_str,end='', flush=True)

 可以把光标移动到行首但不换行
#progress Bar 研究进度条


def print(self, *args, sep=' ', end='
', file=None): # known special case of print
    """
    print(value, ..., sep=' ', end='
', file=sys.stdout, flush=False)
    file:  默认是输出到屏幕,如果设置为文件句柄,输出到文件
    sep:   打印多个值之间的分隔符,默认为空格
    end:   每一次打印的结尾,默认为换行符
    flush: 立即把内容输出到流文件,不作缓存
    """

print源码剖析


原文地址:https://www.cnblogs.com/LXL616/p/10681003.html