摘要:
##列表的加法与乘法 s = [1,2,3]t = [4,5,6]s+t[1, 2, 3, 4, 5, 6]s * 3[1, 2, 3, 1, 2, 3, 1, 2, 3] #嵌套列表matrix = [[1,2,3],[4,5,6],[7,8,9]]matrix =[[1,2,3], [4,5,6 阅读全文
摘要:
##类和对象 x = 520type(x)<class 'int'>y="fish"type(y)<class 'str'>class c: def hello(): print("nh") class c: def get_self(self): print(self) C=c()C.get_se 阅读全文
摘要:
##异常try: 1/0except: print("出错了") 出错了try: 1/1except: print("出错了") 1.0try: 1/0except ZeroDivisionError as e: print(e) division by zerotry: 1/0 520+"fish 阅读全文
摘要:
##函数 #创建和调用函数 def myfunc(): pass myfunc()def myfunc(): for i in range(3): print("I love you") myfunc()I love youI love youI love you #函数参数def myfunc(n 阅读全文
摘要:
##集合 type({})<class 'dict'>type({"one"})<class 'set'>type({"one":1})<class 'dict'>{"fish","python"}{'fish', 'python'}{s for s in "fish"}{'f', 'h', 's' 阅读全文
摘要:
##字典 x={"吕布","关羽"}type(x)<class 'set'>y={"吕布","扣扣不","关羽","关嘻嘻"}type(y)<class 'set'>a={"吕布":"口口布","关羽":"关嘻嘻","刘备":"刘宝贝"}b=dict(吕布="koukoubu",刘备 阅读全文
摘要:
##序列 x = "12321"[1,2,3] + [4,5,6][1, 2, 3, 4, 5, 6][1,2,3] * 3[1, 2, 3, 1, 2, 3, 1, 2, 3]s = [1,2,3]id(s)1970262327360s *=2s[1, 2, 3, 1, 2, 3]id(s)197 阅读全文
摘要:
##字符串 判断回文数 :x = "12321""是回文数" if x == x[::-1] else "不是回文数"'是回文数'x = "12345""是回文数" if x == x[::-1] else "不是回文数"'不是回文数' 大小写字母换来换去的方法:capitalize() casef 阅读全文
摘要:
##元组列表-[元素1,元素2,元素3,。。。。]元组-(元素1,元素2,元素3,。。。。)支持count和index方法。 #代码:rhyme = (1,2,3,4,5,"上山打老虎")rhyme(1, 2, 3, 4, 5, '上山打老虎')rhyme = 1,2,3,4,5,"上山打老虎"rh 阅读全文