分类: Python/Ruby
2021-04-08 17:19:01
# print("hello world")
# a=1
#
# print(id(a))
# a=3
# print(id(a))
#
# # 十进制21转化为二进制
# # 21/2=10........1
# # 10/2=5........0
# # 5/2=2.........1
# # 2/2=1.........0
# # 1/2=0.........1
#
# #从下往上10101
#
# #二进制
# 0b101
# #八进制
# 0o101
# #十六进制
# 0x101
# #其他进制转二进制
# print(bin(0x101))
# #其他进制转八进制
# oct(0x100)
# #其他进制转十进制
# int('0o101',8)
# #其他进制转十六进制
# hex(0b10)
# #布尔类型 True False 是int类型
# a=True
# b=False
# print(isinstance(a,int))
#
# #bool 中int类型 0是false 其他都是True
# print(bool(0))
# #%s 占位符
# print("你好 %s 加油%s" %("中国","打工人"))
# d=12
# e=45
# print(d//5)
# print(d%8)
# print(e**6)
# v=[1,2,6]
# b=v[:]
# print(b)
# f="123"
# g="12"
# print(g in f)
# f=456
# g=45
# print(g == f)
#
# a=10
# b=10
# print(a if a>b else b)
# c="123"
# d="1234"
# print("五星红旗" if c in d else "我爱中国")
#
# result=0;
# for i in range(101):
# result+=i
# i+=1
#
# print(result)
# a=['addd','b','c','d','dd']
# a.append('ff')
# print(a[-1])
# print(a[1:4])
# a={'aa','f',1,5,8,9,4}
# a.add('n')
# for i in range(100000):
# i+=1;
# print(a)
# a=[0,5,4,8,9,6,7,9,7]
# print(a.index(9))
# a.insert(3,898)
# print(a)
# del a[4]
# print(a)
# print(a.pop(1))
# b=set(['ad','ff'])
# print(b)
#
# c={1,2,3}
# d={1,2,555}
# print(c.union(d))
# a={8,9,7,6}
# print(a)
#元组 tuple
# top=(1,2,3,[4,5,9])
# print(top)
# top[-1].append(898)
# print(top)
#字典 dict
# a={1:2,4:4}
# a.update({2:89})
# print(a)
# a[1]=56
# print(a)
# print(len(a))
# print(range(899))
# # 要把range变成对象列表需要用list()函数
#
# print(list(range(89)))
# 地址对象货币代码的值变了,地址变了为不可变对象 ex int 字符串 元组 ,地址不变为 可变对象
# a={1,2,6}
# print(id(a))
# a.add(56)
# print(id(a))
# a=[0,4,5,6,9,8,7,5,1,2,3,6,4,58,7,8,9,6,45,48,787,87,8787,8,87,87]
# print(a[:])
# print(a[::2])
# print(a[:10:2])
# print(a[5:])
# print(a[0:8])
# [expr for iter_var in iterable]
# [expr for iter_var in iterable if cond_expr]
#[i for i in range(101) if i%==0]
# print([i * 8 for i in range(5, 89)])
# print([i for i in range(1, 101) if i % 2 == 0])
# print([[x, y] for x in range(1, 5) for y in range(7)])
# 导包判断是否可以迭代
# from collections.abc import Iterable
# print(isinstance("adcc", Iterable))
# a={'a':1,'v':8,'f':8}
# # print(a.keys())
#拿到的是key
# a={'a':1,'v':8,'f':8}
# for i in a:
# print(i)
#求列表里面的的和
# l=[[1,2],[5,8]]
# for [x,y] in l:
# print('x+y=',x+y)
#生成器返回的是
# c=(i * 2 for i in range(10))
# print(type((i * 2 for i in range(10))))
# print(type([i *2 for i in range(10)]))
# print(next(c))
# print(next(c))#这种超过长度就会报错
#使用循环就不会掉出
# for d in c:
# print(d)