![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
m0_63911789
这个作者很懒,什么都没留下…
展开
-
字符串的判断功能
字符串的开头问题与包含问题#startswith() :判断字符串以什么开头# endswith() :判断字符串以什么结尾# 语法 : 字符串序列.startswith(子串,开始位置下标,结束位置下标)/endswith(子串,开始位置下标,结束位置下标)str1='python'print(str1.startswith('p'))print(str1.startswith('p',2,4))print(str1.endswith('n'))print(str1.endswi原创 2022-03-31 22:21:01 · 63 阅读 · 0 评论 -
字符串常见修改方法_02(理解)
删除空白字符大小写互换与字符串对齐pitalize() :将字符串第一个字符转成大写,其余转成小写str1="hEllo world and itcast and itheima and Python"print(str1.capitalize()) # Hello world and itcast and itheima and python#title() :将字符串中每个单词首字母都转成大写pr...原创 2022-03-31 22:05:18 · 271 阅读 · 0 评论 -
字符串修改功能_01
12 3代码展示#replace() : 修改字符串的内容# 语法: 字符串序列.replace(旧子串,子新串,替换次数)# 替换次数如果超出了子串中出现的次数,表示替换所有这个子串,不写替换次数默认全部替换str1="hello world and itcast and itheima and python"print(str1.replace("and",'he...原创 2022-03-31 21:43:04 · 102 阅读 · 0 评论 -
字符串常用的查找功能
代码展示# find() :检测某个字串是否包含在某个字符串中,如果在则返回这个子串开始位置的下标,如果不在则返回-1.# 格式 :字符串序列.find(子串,开始位置下标,结束位置下标)str1="python helloworld,welcome to China,python"print(str1.find("python"))print(str1.find("python",28,35))print(str1.find("python",30))print(str1.rfi...原创 2022-03-30 22:16:19 · 323 阅读 · 0 评论 -
字符串下标和切片操作
下标操作代码展示# 字符串下标或索引或索引值: 这些字符数据从第一个字符开始顺序分配一个编号,# 使用这个字符编号精确找到某个字符数据# 字符串下标str1="hello python"str2=str1[0]str3=str1[1]print(str2)print(str3)print(str1[2])print(str1[3])运行结果hell切片操作# 切片: 对操作的对象截取其中一部分的操作,字符串,列表,元组都支持切片操作# 格式: [开始原创 2022-03-27 20:23:56 · 331 阅读 · 0 评论 -
输出字符_02——转义字符
两个常见的转义字符代码展示功能# \n :换行符# \t : 制表符,相当于一个tab键(4个空格)print("hello python")print("hello \npython")print("-----------")print('abcd')print("\tabcd")输出结果展示C:\Users\zhao\Anaconda3\python.exe "B:/Pycharm/My ...原创 2022-03-27 10:02:38 · 1303 阅读 · 0 评论 -
输出字符_01——格式化字符
前三个是最常用的代码展示age=19name="zaron"weight=53.5stu_id=3stu_id2=11111111# 我的年龄是 %d 整数print("我的名字是%d" %(age+1))print("我的名字是%d" %(age))# 我的名字是 %s 字符串# 格式化字符串除了可以用 %s,还可以用f '{表达式}'print('我的名字是 %s ' %name)print(f'我的名字是{name},今年{age}岁了')# 我的体重是 %原创 2022-03-26 22:26:58 · 319 阅读 · 0 评论 -
Python数据类型
Python常见数据类型及其应用原创 2022-03-23 20:43:45 · 979 阅读 · 0 评论