随笔分类 -  python

上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 26 下一页
摘要:1、 >>> a = {1,2,3} >>> a {1, 2, 3} >>> type(a) <class 'set'> >>> a.add(4) >>> a {1, 2, 3, 4} >>> b = frozenset({1,2,3}) ## 不可变集合 >>> b frozenset({1, 2 阅读全文
posted @ 2021-03-03 11:54 小鲨鱼2018 阅读(289) 评论(0) 推荐(0)
摘要:1、集合单个增加元素 >>> a = {111,222,333,444} >>> a {444, 333, 222, 111} >>> type(a) <class 'set'> >>> a.add(555) >>> a {555, 333, 111, 444, 222} >>> a.add("aa 阅读全文
posted @ 2021-03-03 11:34 小鲨鱼2018 阅读(3517) 评论(0) 推荐(0)
摘要:1、直接创建 >>> a = {111,"aaa",222,"bbb",555} >>> a {555, 111, 'aaa', 'bbb', 222} >>> type(a) <class 'set'> 2、字符串转换 >>> a = "helloworld" >>> a 'helloworld' 阅读全文
posted @ 2021-03-03 11:25 小鲨鱼2018 阅读(524) 评论(0) 推荐(0)
摘要:1、列表 -- (中括号 + 逗号) >>> a = ["aaa","bbb","ccc","ddd"] >>> a ['aaa', 'bbb', 'ccc', 'ddd'] >>> type(a) <class 'list'> 2、元组 -- (小括号 + 逗号) >>> a = ("a","b" 阅读全文
posted @ 2021-03-02 17:23 小鲨鱼2018 阅读(319) 评论(0) 推荐(0)
摘要:1、 >>> a = dict(a = 111, b = 222, c = 333, d = 444) >>> for i in reversed(a): ## 逆向输出 print(i,a[i]) d 444 c 333 b 222 a 111 2、 >>> a {'a': 111, 'b': 2 阅读全文
posted @ 2021-02-26 09:59 小鲨鱼2018 阅读(692) 评论(0) 推荐(0)
摘要:1、 >>> a = dict(zip(("a","b","c","d"),(111,222,333,444))) >>> a {'a': 111, 'b': 222, 'c': 333, 'd': 444} >>> b = a ## 假复制 >>> b {'a': 111, 'b': 222, ' 阅读全文
posted @ 2021-02-26 09:42 小鲨鱼2018 阅读(311) 评论(0) 推荐(0)
摘要:1、 >>> a = {"a":111,"b":222,"c":333,"d":444} >>> a {'a': 111, 'b': 222, 'c': 333, 'd': 444} >>> del a["a"] >>> a {'b': 222, 'c': 333, 'd': 444} >>> d 阅读全文
posted @ 2021-02-26 09:26 小鲨鱼2018 阅读(2879) 评论(0) 推荐(0)
摘要:1、 >>> a = dict(zip(("a","b","c","d"),(111,222,333,444))) >>> a {'a': 111, 'b': 222, 'c': 333, 'd': 444} >>> type(a) <class 'dict'> >>> a.clear() >>> 阅读全文
posted @ 2021-02-26 09:17 小鲨鱼2018 阅读(543) 评论(0) 推荐(0)
摘要:1、 >>> a = {"a":111,"b":222,"c":333,"d":444,"a":555} ## 如果键重复,则仅保留最后一个键值对 >>> a {'a': 555, 'b': 222, 'c': 333, 'd': 444} 阅读全文
posted @ 2021-02-25 21:50 小鲨鱼2018 阅读(1629) 评论(0) 推荐(0)
摘要:1、 >>> a = dict(a = 111, b = 222, c = 333, d = 444) >>> a["a"] 111 >>> a["c"] 333 >>> b = ("b","d") >>> for i in b: print(a[i]) 222 444 2、 >>> a = dic 阅读全文
posted @ 2021-02-25 21:39 小鲨鱼2018 阅读(171) 评论(0) 推荐(0)
摘要:1、 >>> a = dict(a = 111, b = 222, c = 333, d = 444) >>> a {'a': 111, 'b': 222, 'c': 333, 'd': 444} >>> a["e"] = 555 ## 增加项 >>> a {'a': 111, 'b': 222, 阅读全文
posted @ 2021-02-25 21:35 小鲨鱼2018 阅读(2761) 评论(0) 推荐(0)
摘要:1、 >>> a = {"a":111,"b":222,"c":333,"d":444} >>> a {'a': 111, 'b': 222, 'c': 333, 'd': 444} >>> len(a) 4 >>> type(a) <class 'dict'> 2、 >>> a = dict((( 阅读全文
posted @ 2021-02-25 21:25 小鲨鱼2018 阅读(167) 评论(0) 推荐(0)
摘要:1、 >>> a = ["ccc","aaa","ddd","bbb"] ## 利用列表分片 >>> b = a[::-1] >>> b ['bbb', 'ddd', 'aaa', 'ccc'] 2、 >>> a = ["ccc","aaa","ddd","bbb"] >>> b = 阅读全文
posted @ 2021-02-25 21:03 小鲨鱼2018 阅读(1390) 评论(0) 推荐(0)
摘要:1、 >>> a = ["aaa","bbb","ccc"] ## 列表,中括号,逗号 >>> type(a) <class 'list'> >>> b = ("aaa","bbb","ccc") ## 元组,小括号,逗号 >>> type(b) <class 'tuple'> >>> c = "a 阅读全文
posted @ 2021-02-25 20:35 小鲨鱼2018 阅读(166) 评论(0) 推荐(0)
摘要:zip函数返回有可迭代对象共同组成的元组。 1、 >>> a = "abcde" >>> b = [100,200,300,400,500] >>> c = ("aaa","bbb","ccc","ddd","eee") >>> for i in zip(a,b,c): ## 返回由可迭代对象共同组 阅读全文
posted @ 2021-02-25 16:41 小鲨鱼2018 阅读(108) 评论(0) 推荐(0)
摘要:enumerate返回一个二元组的可迭代对象,二元组就是元素数为二的元组。 1、字符串 >>> a = "erqwu" >>> enumerate(a) <enumerate object at 0x0000018555A1D880> >>> for i in enumerate(a): ## 可迭 阅读全文
posted @ 2021-02-25 16:33 小鲨鱼2018 阅读(707) 评论(0) 推荐(0)
摘要:1、字符串反转 >>> a = "839574" >>> reversed(a) <reversed object at 0x00000215CACA0D60> >>> for i in reversed(a): ## reversed反转为迭代器对象 print(i,end = ";") 4;7; 阅读全文
posted @ 2021-02-25 16:22 小鲨鱼2018 阅读(240) 评论(0) 推荐(0)
摘要:1、字符串排序 >>> a = "349217" >>> b = sorted(a) >>> b ['1', '2', '3', '4', '7', '9'] >>> type(b) ## 返回类型为列表 <class 'list'> >>> c = sorted(a,reverse = True) 阅读全文
posted @ 2021-02-25 16:07 小鲨鱼2018 阅读(149) 评论(0) 推荐(0)
摘要:1、 >>> a = 123 >>> a 123 >>> type(a) <class 'int'> >>> b = float(a) ## 整数转化为浮点 >>> b 123.0 >>> type(b) <class 'float'> >>> c = str(a) ## 整数转化为字符串 >>> 阅读全文
posted @ 2021-02-25 15:13 小鲨鱼2018 阅读(206) 评论(0) 推荐(0)
摘要:tuple函数将可迭代对象转化为元组。 1、 >>> tuple("abcde") ('a', 'b', 'c', 'd', 'e') >>> a = tuple("abcde") ## 字符串作为可迭代对象,将字符串转化为元组 >>> a ('a', 'b', 'c', 'd', 'e') >>> 阅读全文
posted @ 2021-02-25 15:01 小鲨鱼2018 阅读(520) 评论(0) 推荐(0)

上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 26 下一页