03-Python里字符串的常用操作方法二
1、lstrip():删除左侧空白字符
实例:
my_str = ' hello world and my and test and python ' # 原始字符串
print(my_str)
# lstrip() 删除左侧空白字符
my_str1 = my_str.lstrip()
print(my_str1)
结果:
2、rstrip() :删除右侧空白字符
实例:
my_str = ' hello world and my and test and python ' # 原始字符串
print(my_str)
# rstrip() 删除右侧空白字符
my_str2 = my_str.rstrip()
print(my_str2)
结果:
3、strip() 删除两侧空白字符
实例:
my_str = ' hello world and my and test and python ' # 原始字符串
print(my_str)
# strip() 删除两侧空白字符
my_str3 = my_str.strip()
print(my_str3)
结果:
4、ljust() :字符串左对齐
语法: 字符串序列.ljust('长度', 填充字符)
实例:
str_a = 'hello'
new_str_a = str_a.ljust(10, '.')
print(new_str_a)
结果:
5、rjust() :字符串右对齐
语法: 字符串序列.rjust('长度', 填充字符)
实例:
str_a = 'hello'
new_str_b = str_a.rjust(11, '+')
print(new_str_b)
结果:
6、center() :字符串中间对齐
语法: 字符串序列.center('长度', 填充字符)
实例:
str_a = 'hello'
new_str_c = str_a.center(11, '*')
print(new_str_c)
结果:
03-Python里字符串的常用操作方法二的更多相关文章
- 04-Python里字符串的常用操作方法三-判断
1. startswith(): 判断字符串是否以某个子串开始,是则返回True,否则返回False 示例: my_str = 'hello world and my and test and pyt ...
- 01-Python里字符串的常用操作方法--replace()函数
1. replace() 函数 作用: 替换字符串 语法: replace('需要替换的子串', '新的子串', '替换的次数(可不传)') # 当替换次数不传时,默认全部替换 实例一: mystr ...
- 02-Python里字符串的常用操作方法--split()函数和join()函数
1.split() --分割,返回一个列表, 会丢失分割字符 实例: my_str = 'you and me and he' list01 = my_str.split('and') list02 ...
- python中字符串(str)常用操作总结
# 字符串的常用操作方法 (都是形成新的字符串,与原字符串没有关系.) 1.字符串的基本操作之切片 s = 'python hello word' # 取首不取尾,取尾要+1 # 切片取出来的字符串与 ...
- 超详细!盘点Python中字符串的常用操作
在Python中字符串的表达方式有四种 一对单引号 一对双引号 一对三个单引号 一对三个双引号 a = 'abc' b= "abc" c = '''abc''' d = " ...
- python入门基础知识二(字符串的常用操作方法)
下标/索引: a = "I'm interested in Python." print(a[4]) i # 英文的字符串每一个下标/索引对应一个字母(含标点) a = '我喜欢p ...
- Python list列表的常用操作方法
本文主要介绍了Python中列表(List)的详解操作方法,包含创建.访问.删除.排序.切片,乘等操作方法 1.创建列表:把逗号分隔的不同的数据项使用方括号括起来 list = [1,2,3,'Jam ...
- python基础—字符串的常用函数“”
#字符串常用语法name = "wang yan li"print(name.capitalize())#首字母大写print(name.count("n")) ...
- python之字符串的常用操作(转)
1. 字符串的操作 字符串的连接操作 符号: + 格式:str1 + str2 例如:str1 = 'I Love' str2 = 'You!' print(str1 + str2) >> ...
随机推荐
- Reverse for ‘password_reset_complete‘ not found. ‘password_reset_complete‘ is not a valid view funct
关注公众号"轻松学编程"了解更多 原因 在使用xadmin与django 2版本以上修改密码时会报这个错,这是由于django修改密码成功后使用的是success_url参数,而x ...
- layui table中固定表头,弹框缩放之后,表头对不齐问题
新手一枚 直接上解决方案 在layui弹出成功后再渲染表格数据 具体操作就是在layer弹层完成之后的回调中渲染表格数据 layer.open({ type: 1, content: $(&quo ...
- 基于虚拟机安装Linux并利用LVM创建磁盘分区
主要步骤:将磁盘设置为LVM类型,并在这四个分区上创建物理卷.卷组和逻辑卷,最后将逻辑卷挂载.电脑使用Windows10 企业版 LTSC 操作系统.虚拟机使用VMware15.5 pro . 1.安 ...
- 【Kata Daily 191010】Grasshopper - Summation(加总)
题目: Summation Write a program that finds the summation of every number from 1 to num. The number wil ...
- Loading descriptor for XXX.'has encountered a problem' A internal error occured during:"Loading ....."
在JavaWeb部署Tomcat后启动Jsp发现这样的报错 这可能是Tomcat的运行欢迎有问题,按下图所示打开Tomcat界面.Servers目录就是当前工作空间对所有工程适用的的Tomcat环境, ...
- 带货直播源码开发采用MySQL有什么优越性
MySQL是世界上最流行的开源关系数据库,带货直播源码使用MySQL,可实现分钟级别的数据库部署和弹性扩展,不仅经济实惠,而且稳定可靠,易于运维.云数据库 MySQL 提供备份恢复.监控.容灾.快速扩 ...
- Thinkphp3.2 cms之登陆模块
<?php /** * Created by dreamcms. * User: Administrator * Date: 2016/9/5 * Time: 17:15 */ namespac ...
- 左值 lvalue,右值 rvalue 和 移动语义 std::move
参考文章: [1] 基础篇:lvalue,rvalue和move [2] 深入浅出 C++ 右值引用 [3] Modern CPP Tutorial [4] 右值引用与转移语义 刷 Leetcode ...
- C# 集合类(二)
C# 集合类自己经常用到: 数组(Array).动态数组(ArrayList).列表(List).哈希表(Hashtable).字典(Dictionary),对于经常使用的这些数据结构,做一个总结,便 ...
- maven profile filter 线上线下分开打包配置
maven自动选择不同的配置文件打包profile+filter 1. profile: [要点:] activeByDefault默认激活,不用再mvn命令时指定额外参数: [注意:] 使用非默认的 ...