随笔分类 -  python

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 26 下一页
摘要:示例: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter 更新pip: python -m pip install --upgrade pip 阅读全文
posted @ 2021-11-19 12:08 小鲨鱼2018 阅读(217) 评论(0) 推荐(0)
摘要:python中global关键字实现在函数内部对全局变量进行修改。 1、测试 >>> v = 10 >>> def test(): v = 5 print(v) >>> test() 5 >>> v ## 这说明在函数内部修改的全局变量只能在函数内部生效,不会真正影响全局变量 10 加global关 阅读全文
posted @ 2021-05-09 23:00 小鲨鱼2018 阅读(1234) 评论(0) 推荐(0)
摘要:python中创建字典、字典的访问 1、 >>> test1 = {"aaa":111,"bbb":222,"ccc":333} >>> test1 {'aaa': 111, 'bbb': 222, 'ccc': 333} >>> type(test1) <class 'dict'> >>> 2、 阅读全文
posted @ 2021-05-03 20:26 小鲨鱼2018 阅读(187) 评论(0) 推荐(0)
摘要:1、 问题 >>> test2 = dict((('F',20),('i',40),('s',80))) Traceback (most recent call last): File "<pyshell#171>", line 1, in <module> test2 = dict((('F',2 阅读全文
posted @ 2021-05-03 19:17 小鲨鱼2018 阅读(886) 评论(0) 推荐(0)
摘要:python中字符串拼接的三种方法。 1、加号拼接 >>> a = "abcd" >>> b = "xyzm" >>> a 'abcd' >>> b 'xyzm' >>> a + b 'abcdxyzm' 2、join拼接 >>> c = ["abcd","xyzm"] >>> c ['abcd', 阅读全文
posted @ 2021-05-01 23:16 小鲨鱼2018 阅读(657) 评论(0) 推荐(0)
摘要:python中字符串的格式化。 1、format 位置参数 >>> "{0} and {1}".format("aaa","bbb") 'aaa and bbb' >>> "{0},{1} and {2}".format("aaa","bbb","ccc") 'aaa,bbb and ccc' 关键 阅读全文
posted @ 2021-05-01 23:11 小鲨鱼2018 阅读(168) 评论(0) 推荐(0)
摘要:python中字符串的拼接。 1、 >>> test1 = ["aaa","bbb","ccc","ddd","eee"] >>> test1 ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] >>> "-".join(test1) 'aaa-bbb-ccc-ddd-eee' 阅读全文
posted @ 2021-05-01 22:56 小鲨鱼2018 阅读(74) 评论(0) 推荐(0)
摘要:1、问题 [root@centos7 Python-3.9.4]# ln -s python /usr/bin/python [root@centos7 Python-3.9.4]# python -bash: /usr/bin/python: Too many levels of symbolic 阅读全文
posted @ 2021-05-01 22:52 小鲨鱼2018 阅读(3399) 评论(0) 推荐(0)
摘要:python中拆分字符串 1、 >>> test1 = "abxcdxefxfh" >>> test1 'abxcdxefxfh' >>> test1.split(sep = "x") ['ab', 'cd', 'ef', 'fh'] 阅读全文
posted @ 2021-05-01 21:51 小鲨鱼2018 阅读(400) 评论(0) 推荐(0)
摘要:python中替换字符串中特定字符。 1、 >>> test1 = "abdadcadadfa" >>> test1 'abdadcadadfa' >>> test1.replace("a","x") 'xbdxdcxdxdfx' >>> test1.replace("a","x",2) ## 指定 阅读全文
posted @ 2021-05-01 21:48 小鲨鱼2018 阅读(2717) 评论(0) 推荐(0)
摘要:1、返回第一个出现的索引 >>> test1 'absacaxy' >>> test1.find("a") 0 2、返回特定字符的所有索引 >>> test1 'absacaxy' >>> b = test1.count("a") >>> c = -1 >>> for i in range(b): 阅读全文
posted @ 2021-05-01 21:34 小鲨鱼2018 阅读(3795) 评论(0) 推荐(0)
摘要:python中查找字符串中字符出现的次数 1、 >>> test1 = "absacaxy" >>> test1.count("a") 3 >>> test1.count("a",0,4) ## 设置查找范围 2 2、统计所有字符出现的次数 >>> test1 = "abdeaceb" >>> a 阅读全文
posted @ 2021-05-01 21:27 小鲨鱼2018 阅读(2082) 评论(0) 推荐(0)
摘要:1、 删除左边空白 >>> test1 = " abcd " >>> test1 ' abcd ' >>> test1.lstrip() 'abcd ' 2、删除右边空白 >>> test1 ' abcd ' >>> test1.rstrip() ' abcd' 3、删除两边空白 >>> test1 阅读全文
posted @ 2021-05-01 21:20 小鲨鱼2018 阅读(704) 评论(0) 推荐(0)
摘要:1、大写改为小写 >>> test1 = "abCDEfg" >>> test1 'abCDEfg' >>> test1.upper() 'ABCDEFG' 2、小写变大写 >>> test1 'abCDEfg' >>> test1.lower() 'abcdefg' >>> test1 'abCD 阅读全文
posted @ 2021-05-01 21:14 小鲨鱼2018 阅读(696) 评论(0) 推荐(0)
摘要:python中zip函数 1、python中zip函数用于返回由可迭代参数共同组成的元组。 长度不一致时,以短的序列进行迭代。 >>> test1 = ["aaa","bbb","ccc","ddd"] >>> test2 = (111,222,333,444,555) >>> test3 = "a 阅读全文
posted @ 2021-05-01 20:44 小鲨鱼2018 阅读(620) 评论(0) 推荐(0)
摘要:python中enumerate函数。 1、python中enumerate函数 enumerate函数的应用对象为序列(列表、元组、字符串), 返回一个由二元组组成的可迭代对象,二元组由可迭代参数的索引号及其对应的元素组成。 列表 >>> test1 = ["aaa","bbb","ccc"] > 阅读全文
posted @ 2021-05-01 20:37 小鲨鱼2018 阅读(604) 评论(0) 推荐(0)
摘要:1、反转 永久反转 >>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', 'xx', 'bb'] >>> test1.reverse() >>> test1 ['bb', 'xx', 'dd', 'cc', 'aa', 'cc', 'aa' 阅读全文
posted @ 2021-04-28 21:35 小鲨鱼2018 阅读(276) 评论(0) 推荐(0)
摘要:python中返回列表中指定元素的所有索引。 1、基本用法 >>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', 'xx', 'bb'] >>> test1.index("aa") 0 2、返回所有索引 >>> test1 ['aa', 'bb', 阅读全文
posted @ 2021-04-28 21:22 小鲨鱼2018 阅读(3064) 评论(0) 推荐(0)
摘要:python中返回列表元素的每一个元素的频数。 1、单个元素频数 >>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', 'xx', 'bb'] >>> test1.count("aa") 3 2、 >>> test1 ['aa', 'bb', 'a 阅读全文
posted @ 2021-04-28 20:55 小鲨鱼2018 阅读(251) 评论(0) 推荐(0)
摘要:python中列表元素的去重复 1、方法1 >>> test1 = ["aa","bb","aa","cc","aa","cc","dd","xx","bb"] >>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', &# 阅读全文
posted @ 2021-04-28 20:35 小鲨鱼2018 阅读(250) 评论(0) 推荐(0)

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 26 下一页