day12-2018-11-2 内置函数

lst = ["唐伯虎", "小娟", "张鹤伦", "烧饼"]

# it = lst.__iter__()
# print(it.__next__())
# print(it.__next__())
# print(it.__next__())
# print(it.__next__())


# it = iter(lst) # 获取迭代器
# print(it.__next__())
# print(next(it)) # 相当于 __next__()
# print(next(it))
# print(next(it))

# s = "胡辣汤"
# print(id(s)) # 2175466552560  内存地址的int形式
# print(hash(s)) # 唯一的数字, 为了存储 6492443426362943124 8426701594033488624
# print(hash(s))
#
# print(hash(13)) # 数字的哈希值就是它本身

# 4342805289873345757  哈希值不能做密码-> md5
# 4342805289873345757

# 4931740966047962723
# 4931740966047962723

# print(help(str)) # 帮我看看str是啥


# a = 10
# # a() # 不可以被调用    ()
#
# def chi():
#     print("吃什么呢")
# # chi()
#
# print(callable(a)) # False
# print(callable(chi))  # True


# def dai(fn):
#     if callable(fn): # 判断参数是否可以被调用
#         fn()
#     else:
#         print("不能被调用")
#
# dai(10)

# print(dir(str))

# 255 255 255 255
# 11111111 11111111 11111111 11111111
# print(bin(256)) # 0b100 1  10  11  100
# print(oct(8)) # 0o10
# print(hex(15)) # 十六进制-> 0-9 abcdef

# print(int(0x10)) # 十进制

# float 浮点数
# print(type(0.0112))

# complex 复数 = 实数+虚数
# 实数: 有理数+无理数(无限不循环小数 pi)
# i ** 2 = -1 虚无缥缈的数
# matlab

# print(abs(3)) # 绝对值. 取模
#

# print(divmod(20, 555555555555))

# 不太好用.
# print(round(4.4)) # 如果整数位是偶数靠近偶数进行舍弃 -
# print(round(5.4)) # 如果整数位是偶数靠近偶数进行舍弃 +
# 自定义的
# def func(num): # "5.4123456"  ["5", "4123456"]
#     fu = 1
#     if num < 0:
#         fu = -1
#
#     num = abs(num)
#     snum = str(num)
#     if int(snum.split(".")[1][0])>=5:  # 入
#         return (int(snum.split(".")[0])+1)*fu
#     else:   #  舍
#         return int(snum.split(".")[0])*fu
#
# print(func(11.99))

# print(pow(10,2,3))
# print(10**2)
# 1+2+3+4+5+6+7...100
# print(sum(range(101))) # range(101) 可迭代对象
# sum(可迭代对象)

# print(max(1,2,3,-4,5,6,7,8,9))
# print(min(1,2,3,-4,5,6,7,8,9))

# lst = ["哈哈", "呵呵", "吼吼"]
# for i in range(len(lst)):
#     print(i)
#     print(lst[i])

# for i,el in enumerate(lst, 100): # (索引, 元素)
#     print(i, el)

# lst = ["电脑", "键盘", "鼠标"]
# for i, el in enumerate(lst, 1):
#     print(i, el)

# print(all([1,2,True,0])) # False   and
# print(any([1,'',0])) #  True   or

# zip 拉链函数
# lst1 = ["胡歌", "霍建华", "彭于晏", "吴彦祖"]
# lst2 = [37,46,50]
# lst3 = ["仙剑三", "花千骨", "湄公河行动", "警察故事"]
#
# z = zip(lst1, lst2, lst3) # 第0个放一起, 第一个放一起, 第二个放一起. 水桶效应
# print("__iter__" in dir(z)) # 可以迭代
# for el in z:
#     print(el)

# lst = (1,2,3,4,5)
# new_lst = reversed(lst) # 通用
# for el in new_lst:
#     print(el)

# s = "哈哈哈哈"
# for c in s:
#     print(c)
#
# lst = {1,2,3,4,5}
# for c in lst:
#     print(c)

# st = "⼤家好, 我是麻花藤"
# s = slice(1, 6, 2)
# print(st[s])
# st[::]
# lst1 = [1,2,3,4,5,6,7,8,9]
# lst2 = [1,2,3,4,5,6,7,8,9]
# lst3 = [1,2,3,4,5,6,7,8,9]
# lst4 = [1,2,3,4,5,6,7,8,9]
# lst5 = [1,2,3,4,5,6,7,8,9]
# lst6 = [1,2,3,4,5,6,7,8,9]
# lst7 = [1,2,3,4,5,6,7,8,9]
# lst8 = [1,2,3,4,5,6,7,8,9]
# lst9 = [1,2,3,4,5,6,7,8,9]
# lst10 = [1,2,3,4,5,6,7,8,9]
# lst1[s]
# lst1[s]
# lst1[s]
# lst1[s]
# lst1[s]
# lst1[s]
# lst1[s]
# lst1[s]

# 字符串
# print(format('test', '<20')) # 左对⻬  cener(20)
# print(format('test', '>20')) # 右对⻬
# print(format('test', '^20')) # 居中

# # 数值
# print(format(3, 'b')) # ⼆进制  11
# print(format(97, 'c')) # 转换成unicode字符 a
# print(format(11, 'd')) # ⼗进制  11
# print(format(11, 'o')) # ⼋进制 13
# print(format(11, 'x')) # ⼗六进制(⼩写字⺟) b
# print(format(11, 'X')) # ⼗六进制(⼤写字⺟) B
# print(format(11, 'n')) # 和d⼀样 11
# print(format(11)) # 和d⼀样 11
# # 浮点数
# print(format(123456789, 'e')) # 科学计数法. 默认保留6位⼩数
# print(format(123456789, '0.2e')) # 科学计数法. 保留2位⼩数(⼩写)
# print(format(123456789, '0.2E')) # 科学计数法. 保留2位⼩数(⼤写)
# print(format(1.23456789, 'f')) # ⼩数点计数法. 保留6位⼩数
# print(format(1.23456789, '0.2f')) # ⼩数点计数法. 保留2位⼩数
# print(format(1.23456789, '0.10f')) # ⼩数点计数法. 保留10位⼩数
# print(format(1.23456789e+10000, 'F')) # ⼩数点计数法. INF 无穷

# 1.2508132548754585
# print(format(1.2508132548754585,"0.2f"))


# s = "今天星期五"
# print(s.encode("utf-8"))
# print(bytes(s, encoding="utf-8")) # 网络通信要用到它

# s = "内存"
# m = memoryview(s.encode("utf-8")) # 不给程序员用的
# print(m)


# print(ord("中")) # 查看编码位置
#
# print(chr(20013))   # 查看某位置的编码是谁
# for i in range(65536):
#     print(chr(i), end=" ")

# print(ascii("中国韩国日本新加坡")) # 判断你的文字是否在ascii里面. 也能获取到unicode
# 在字符串中使用\表示的转义
# \n 换行  \t制表符   \r回车
# \\   \
# \"  "
# \'   '
# # python使用的字符串实际上和c的字符串是不一样的. python对字符串进行了处理
# print("你好我叫\\刘德\n华我叫周润发")
# # 字符串最应该显示的样子. 最底层, 最官方的显示效果
# print(repr("你好我叫\\刘德\n华我叫周润发")) # __repr__ __str___

# print(r"你给我显\示一下\n") # r"" 原样输出
# print(r"\/\d+\w|\d?*")

# name = "胡辣汤"
# # 3.6以上
# print(f"我想吃{name}") # f format  {占位赋值}
# # print("我想吃%s" %  name)


# code = "1+2+3+5"
# ret = eval(code) # 直接执行字符串类型的代码.  有返回值
# print(ret)


# code = "n = 16"
# exec(code)
# print(n) # 16

# code = input("请输入你要执行的代码")
# exec(code) # 执行代码. 没有返回值
# exec和eval 都不可以一次性执行大段的代码(字符串).


# code="1+2+3+4+5"
# c = compile(code, "", mode="eval")
# print(eval(c))

# code = """
# for i in range(10):
#     print(i)
# for j in range(10):
#     print(j)
# """
# c = compile(code, "", mode="exec")
# exec(c) # 执行代码

# code = """name = input('请输入你的名字')"""
# c = compile(code, "", mode="single") # single 有交互
# exec(c)
# print(name) # pycharm的提示有的时候是不对的

# 可以把字符串类型的数据转化成具体的某些数据
# qianduan = "[1,2,3,4,5]" # json
# lst = eval(qianduan)
# print(lst) # 列表

猜你喜欢

转载自www.cnblogs.com/VastTry/p/9898069.html
今日推荐