python基础
BOBO_GO
每天进步多一点
展开
-
python新增语法f-string
x=12y=15print(f'{x+y}') #python3.6#27print(f'{x+y=}') #python3.8#12+15=27dict={'a':100,'b':200}print(f'{dict["a"]}')原创 2020-07-29 08:40:44 · 152 阅读 · 0 评论 -
字符串
内建函数方法 描述string.capitalize()把字符串的第一个字符大写string.center(width)返回一个原字符串居中,并使用空格填充至长度 width 的新字符串string.count(str, beg=0, end=len(string))返回 str 在 string 里面出现的次数,如果 beg 或者 end 指定则返回指定范围内 str 出...原创 2018-12-12 17:14:12 · 61 阅读 · 0 评论 -
字典
内置函数Python字典包含了以下内置函数:序号 函数及描述1 cmp(dict1, dict2)比较两个字典元素。2 len(dict)计算字典元素个数,即键的总数。3 str(dict)输出字典可打印的字符串表示。4 type(variable)返回输入的变量类型,如果变量是字典就返回字典类型。Python字典包含了以下内置方法:内置方法序号 函数及描述1 ...原创 2018-12-12 17:07:13 · 81 阅读 · 0 评论 -
列表&元组
列表的函数1 cmp(list1, list2)比较两个列表的元素2 len(list)列表元素个数3 max(list)返回列表元素最大值4 min(list)返回列表元素最小值5 list(seq)将元组转换为列表列表的方法1 list.append(obj)在列表末尾添加新的对象2 list.count(obj)统计某个元素在列表中出现的次数3 list...原创 2018-12-12 16:54:39 · 228 阅读 · 0 评论 -
逻辑运算符
'''x or y x True,则返回x'''print(1 or 2) # 1print(3 or 2) # 3print(0 or 2) # 2print(0 or 100) # 100print(2 or 100 or 3 or 4) # 2print(0 or 4 and 3 or 2)'''x and y x True,则返回y'''print(1 an...原创 2018-12-12 16:41:23 · 89 阅读 · 0 评论 -
编码
01010100 新11010000 开11010100 一01100000 家11000000 看11000000 看01010100011101110101011110110A B C01000001 01000010 01000011电报,电脑的传输,存储都是01010101最早的'密码本' ascii 涵盖了英文字母大小写,特殊字符,数字。01010101asc...原创 2018-12-12 16:37:55 · 121 阅读 · 0 评论 -
Python2和Python3的差异
基本语法差异核心类差异Python3对Unicode字符的原生支持Python2中使用 ASCII 码作为默认编码方式导致string有两种类型str和unicode,Python3只支持unicode的string。python2和python3字节和字符对应关系为:Python3采用的是绝对路径的方式进行import。Python2中相对路径的import会导致标准库导入变得困难(...转载 2018-12-28 08:58:44 · 92 阅读 · 0 评论