接上次补充:

s = "username\temail\tpassword\naaa\taa@qq.com\t123\nusername\temail\tpassword\naaa\taa@qq.com\t123"
a = s.expandtabs(20) #断句,以20为单位,不够就自动补齐20个
print(a)

运算结果:

username            email               password
aaa aa@qq.com 123
username email password
aaa aa@qq.com 123 Process finished with exit code 0

其他功能:

1.

#判断当前输入是否为数字
test = '②'
a1 = test.isdecimal() #仅支持数字
a2 = test.isdigit() #支持特殊符号和数字
a3 = test.isnumeric() #支持所有包括中文
print(a1,a2,a3)

运算结果:

False True True

Process finished with exit code 0

2.

test = 'sjalfaj\tafaaf'
a1 = test.isprintable() # 是否存在不可显示的字符
print(a1)

运算结果:

False

Process finished with exit code 0
test = 'sjalfajafaaf'
a1 = test.isprintable() # 是否存在不可显示的字符
print(a1)

运算结果:

True

Process finished with exit code 0

3.判断字符串里是否全是空格

test = 'sjalfa   jafaaf'
a1 = test.isspace() # 是否全是空格
print(a1)

运算结果:

False

Process finished with exit code 0

4.判断是否是标题(首字母大写)

test = 'sjalfa   jafaaf'
a1 = test.istitle()
print(a1)

运算结果:

False

Process finished with exit code 0

5.变成标题

test = 'sjalfa   jafaaf'
a1 = test.istitle()
a2 = test.title()
print(a1)
print(a2)

运算结果:

False
Sjalfa Jafaaf Process finished with exit code 0

6.

#将字符串中的每一个元素按照指定分隔符进行拼接
test = '你好啊猪头'
print(test)
t = ' '
a = t.join(test) #或者 把t.join(test)改成' '.join(test)
print(a)

运算结果:

你好啊猪头
你 好 啊 猪 头 Process finished with exit code 0

7.填充

test = 'abcd'
a = test.ljust(20,'*')
a1 = test.center(20,'中')
print(a)
print(a1)

运算结果:

abcd****************
中中中中中中中中abcd中中中中中中中中 Process finished with exit code 0

8.只用00填充

test = 'abcd'
a = test.zfill(20) print(a)

运算结果:

0000000000000000abcd

Process finished with exit code 0

9.

test = 'ABCD'
a = test.islower() # 判断是否为小写
a1 = test.lower() # 全部变成小写 print(a,a1)

运算结果:

False abcd

Process finished with exit code 0

10.

test = 'abcd'
a = test.isupper() # 判断是否为大写
a1 = test.upper() #变成大写 print(a,a1)

运算结果:

False ABCD

Process finished with exit code 0

11.去掉空白(换行\n,空格\t也能去掉)

test = '   abcd    '
a = test.lstrip() # 去掉左边空白
#a1 = test.rstrip() #去掉右边空白
#a2 = test.strip() # 去掉全部空白
print(a)

12.移除指定字符串

test = 'abcd'
a = test.lstrip("a") print(a)

运算结果:

bcd

Process finished with exit code 0

13.分割

test = 'lovesdcvvf'
a = test.partition('v') #只能将整个字符串分割成3份
a1 = test.rpartition('v') #从右开始分割成3份
a2 =test.split("v",2) #全部分割
a3 = test.rsplit() #从右开始全部分割
print(a)
print(a1)
print(a2)
print(a3)

运算结果:

('lo', 'v', 'esdcvvf')
('lovesdcv', 'v', 'f')
['lo', 'esdc', 'vf']
['lovesdcvvf'] Process finished with exit code 0

14.

test = 'adfsdf\nsafafsad\ndsaf'
a = test.splitlines(True) # 只能根据换行分割, 布尔值用来是否显示换行符
print(a)

运算结果:

['adfsdf\n', 'safafsad\n', 'dsaf']

Process finished with exit code 0

15.

test = 'adfsdf\nsafafsad\ndsaf'
a = test.startswith('a') #判断是否以a开头的
b = test.endswith("a") #判断是否以a结尾
print(a)
print(b)

运算结果:

True
False Process finished with exit code 0

16.大小写转换

test = 'abc'
a = test.swapcase()
print(a)

运算结果:

ABC

Process finished with exit code 0

python学习--13 基本数据类型 2的更多相关文章

  1. Python学习笔记 - day3 - 数据类型及运算符

    Python的数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同 ...

  2. 记录我的 python 学习历程-Day03 数据类型 str切片 for循环

    一.啥是数据类型 ​ 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能呀,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,"汉"是文字,否则它是分 ...

  3. python学习第九天数据类型列表创建,查找操作方法

    数据类型中列表是整个python最常用的数据类型,列表最常用的方法就是创建,增删改查,切片,循环以及排序等系列操作,任何操作都离不开增删改查操作,这样很容记住操作方法 1,列表的创建 list=[] ...

  4. Python学习-字符编码, 数据类型

    本篇主要内容: 字符编码 Python中的数据类型有哪些 类型的一些常用操作及方法 一.字符编码 编码解释的大部分内容摘自廖雪峰老师教程中的讲解,点击跳转. 简单介绍: 我们知道计算机只能处理数字,如 ...

  5. python学习03-数据类型

    一.基本数据类型--数字 布尔型 bool型只有两个值:True和False 之所以将bool值归类为数字,是因为我们也习惯用1表示True,0表示False. 以下是布尔值是False的各种情况: ...

  6. Python学习手册之数据类型

    在上一篇文章中,我们介绍了 Python 的异常和文件,现在我们介绍 Python 中的数据类型. 查看上一篇文章请点击:https://www.cnblogs.com/dustman/p/99799 ...

  7. python学习笔记(数据类型)

    python数据类型: int 类型 float 小数类型 string 字符串 布尔类型 a = True b = False 1.列表,也称数组或list或array.它的表达方式通过下标或索引或 ...

  8. python学习道路(day2note)(数据类型,运算符,字符串,列表)

    一,数据类型 1.1数字 数字分为int(整型),long(长整型),float(浮点型) 1.1.1 int整型的取值范围为 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31- ...

  9. python学习笔记二 数据类型(基础篇)

    Python基础 对于Python,一切事物都是对象,对象基于类创建         不同类型的类可以创造出字符串,数字,列表这样的对象,比如"koka".24.['北京', '上 ...

随机推荐

  1. Mysql远程无法连接

    #登陆mysql $ mysql -uroot -p mysql> use mysql; mysql> update user set host = '%' where user = 'r ...

  2. [PKUSC2018]最大前缀和——状压DP

    题目链接: [PKUSC2018]最大前缀和 设$f[S]$表示二进制状态为$S$的序列,任意前缀和都小于等于$0$的方案数. 设$g[S]$表示二进制状态为$S$的序列是整个序列的最大前缀和的方案数 ...

  3. 走进JavaWeb技术世界8:浅析Tomcat9请求处理流程与启动部署过程

    谈谈 Tomcat 请求处理流程 转自:https://github.com/c-rainstorm/blog/blob/tomcat-request-process/reading-notes &l ...

  4. 使用LAS数据集创建DEM和DSM

    作为 LAS 数据集转栅格工具的输入.大多数情况下,此工具的栅格化通过点的快速分组来完成.由于激光雷达相比较于其他采样技术比较密集,所以许多人相信分组已经足够了,不需要更耗时的插值方法.可以证明上述观 ...

  5. C# - ZIP 压缩流

    C# - ZIP 压缩流 参考资料 https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive?view= ...

  6. java spark list 转为 RDD 转为 dataset 写入表中

    package com.example.demo; import java.util.ArrayList; import java.util.Arrays; import java.util.Hash ...

  7. netty 聊天室

    https://blog.csdn.net/qq_37372007/article/details/82937584 使用netty实现一个多人聊天室--failed: Error during We ...

  8. BitmapFactory: inSampleSize 的一些思考

    一. BitmapFactory.Options 中inSampleSize的取值问题 关于inSampleSize的取值问题Google已经给出了一个推荐的算法:(https://developer ...

  9. Intel AI Cloud 使用

    1.申请AI Cloud A ‘training-ready’ hardware like Amazon® EC2, Intel® AI DevCloud, or a GPU-based system ...

  10. maven项目如何从私服nexus中下载依赖包

    maven项目如何从私服nexus中下载依赖包   解决方法: 1.打开maven的config目录中settings.xml文件 2.在<profile></profiles> ...