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) >> ...
随机推荐
- pycharm配置django rest framework
安装django rest framework pip install 添加rest_framework app 在settings.py INSTALLED_APPS = [ 'django.co ...
- Java学习的第三十八天
例3.4. package bgio; public class cjava { public static void main(String[]args) { int i=1; int sum=0; ...
- 网络编程NIO:BIO和NIO
BIO BIO(Blocking I/O),同步阻塞,实现模式为一个连接一个线程,即当有客户端连接时,服务器端需为其单独分配一个线程,如果该连接不做任何操作就会造成不必要的线程开销.BIO是传统的Ja ...
- Dorado download注意事项
uploader/uploader-SNAPSHOT uploader/uploader-RELEASE .....使用需要注意!
- react 实现组件嵌套以及子组件与父组件之间的通信
当子组件触发onChange事件时,实际调用的是父组件中的handelSelect函数,通俗来说就是父组件通过属性handleSelect实现与子组件之间的通信. 父组件:SignupForm 子组件 ...
- 【SpringCloud】01.常见软件架构的区别
MVC.RPC.SOA.微服务架构的区别: 一.MVC架构 MVC架构就是一种单体架构. 代表技术:Struts2.SpringMVC.Spring.Mybatis等等. 二.RPC架构 RPC(Re ...
- php post请求https
<?php $url = 'https://www.xxx.com'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); c ...
- springboot-rabbitmq之hello-world(一)
概念介绍 这里引用rabbit官网的一张图 image.png 大概意思就是生产着把消息发送到队列然后消费者消费消息 springboot实现 hello-world比较简单这里直接上代码 生产者 声 ...
- 80%人会答错的JS基础面试题
这套题第一道题难度最大,我第一遍的回答居然也错的,我悲观估计80%的JavaScript从业人员都答不完全准确 []==![] 得到什么? false, 你还需要看看基础 true, 恭喜你答对了,你 ...
- 如何在所有的mon的损坏情况下将数据恢复如初
本篇主题 在mon无法启动,或者所有的mon的数据盘都损坏的情况下,如何把所有的数据恢复如初 写本章的缘由 在ceph中国的群里有看到一个技术人员有提到,在一次意外机房掉电后,三台mon的系统盘同时损 ...