上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页
摘要: 封装 class Turtle: head = 1 eyes = 2 leg = 4 shell = True def crawl(self): print("人们总抱怨我动作慢吞吞的,殊不知如不积跬步,无以至千里的道理。") def run(self): print("虽然我行动很慢,但如果遇到危 阅读全文
posted @ 2022-08-05 09:11 tuyin 阅读(36) 评论(0) 推荐(0)
摘要: 求一个数的阶乘 # 迭代方法实现 def factIter(n): result = n for i in range(1, n): result *= i return result print(factIter(10)) # 递归方法实现 def funC(n): if n == 1: retu 阅读全文
posted @ 2022-08-05 08:51 tuyin 阅读(29) 评论(0) 推荐(0)
摘要: 创建和调用函数 # I Love You # I Love You # I Love You def myfunc(): for i in range(3): print("I Love You") myfunc() 函数的参数 # I Love python # I Love python # I 阅读全文
posted @ 2022-08-05 08:48 tuyin 阅读(58) 评论(0) 推荐(0)
摘要: 创建集合 # 集合,无序 # 创建集合 # {'Love', 'Python'} print({"Love", "Python"}) # {'o', 'h', 't', 'n', 'P', 'y'} print({s for s in "Python"}) # {'o', 'h', 't', 'n' 阅读全文
posted @ 2022-08-05 00:07 tuyin 阅读(27) 评论(0) 推荐(0)
摘要: x = {"卢布", "关羽"} print(type(x)) y = {"卢布":"小布布", "关羽":"小鱼鱼"} y["刘备"] = "小贝贝" print(y) print(y["卢布"]) 创建字典的方式 a = {'卢布': '小布布', '关羽': '小鱼鱼', '刘备': '小贝贝 阅读全文
posted @ 2022-08-05 00:05 tuyin 阅读(115) 评论(0) 推荐(0)
摘要: sorted方法 t = ["FishC", "Apple", "Book", "Banana", "Pen"] # sorted方法只是比较首个字母的ASCALL值,如果第一个字母相同就比较第二个字母 # ['Apple', 'Banana', 'Book', 'FishC', 'Pen'] s 阅读全文
posted @ 2022-08-05 00:01 tuyin 阅读(42) 评论(0) 推荐(0)
摘要: # list(),tuple(),str() # 字符串变成列表(list) print(list("Loveyou")) # ['L', 'o', 'v', 'e', 'y', 'o', 'u'] # 元组变成列表(list) print(list((1, 2, 3, 4, 5))) # [1, 阅读全文
posted @ 2022-08-04 23:59 tuyin 阅读(48) 评论(0) 推荐(0)
摘要: 确定回文数 """什么是回文数?正读和倒读都有意义的文字称为“回文”。例如,小白是一个名字,如果反过来,白小,也可以是一个人名, 这个人姓小名白。王融有诗《春游回文诗》中的诗句“风朝指锦幔,月晓照莲池”,反读也是有意义的,不信你读读。 而“回文数”,则是一种数字。例如,65856,这个数正读是658 阅读全文
posted @ 2022-08-04 23:56 tuyin 阅读(135) 评论(0) 推荐(0)
摘要: a = (1, 2, 3, 4, 5, "上山打老虎") # (1, 2, 3, 4, 5, '上山打老虎') print(a) # 4 print(a[3]) # (1, 2, 3, 4, 5, '上山打老虎') print(a[:]) # (1, 3, 5) print(a[::2]) # (' 阅读全文
posted @ 2022-08-04 23:46 tuyin 阅读(42) 评论(2) 推荐(0)
摘要: 列表输出 ary = [1, 2, 3, 4, "是SV"] print(ary) for i in ary: print(i) # 输出列表的最后一个元素 length = len(ary) print(ary[length-1]) print(ary[-1]) # [1, 2, 3] print 阅读全文
posted @ 2022-08-04 23:45 tuyin 阅读(27) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页