#+ Python
对于python的基础语法,应用
小梓在努力
这个作者很懒,什么都没留下…
展开
-
Python的input()函数
input()函数 无论输入的为何种类型,都会返回字符串类型 例如: x=input() print(type(x)) 且在字符串类型下是不允许算术运算的,否则会报错 x=input() print(x+1) 若想要返回其他类型,则需要强制转换 最常用的方法为在输入时强制转换 x = int(input()) y = int(input()) print(x+y) ...原创 2022-03-11 19:32:39 · 2283 阅读 · 0 评论 -
Python中构造字符串
Python中构造字符串 采用str()函数 a=str('i am a girl') print(a) 结果: 用引号 s='i am a cute girl' ss=''i like Python'' p='''what do you like i like codeing''' #三个引号支持多行输入 %s b='%s'%'i am a student' print(b) ![在这里插入图片描述](https://img-blog.csdnimg.cn/ae65643e5fb34dec9原创 2022-03-25 16:58:18 · 786 阅读 · 0 评论 -
Python的re库和正则表达式
re库是python的内置模块,不需要安装,直接导入便可以使用 re库的正则处理方法: re.match() re.match(pattern,string,flags=0) 从头开始匹配,匹配成功返回match对象,否则返回None import re pattern=r'\d\.\d+'#+用来限制次数(一次或多次 m='a1.72mw72yz' match=re.match(pattern,m) print(match) import re pattern=r'\d\.\d+'#+原创 2022-03-26 19:21:40 · 1312 阅读 · 0 评论