接上次补充:

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

运算结果:

  1. username email password
  2. aaa aa@qq.com 123
  3. username email password
  4. aaa aa@qq.com 123
  5.  
  6. Process finished with exit code 0

其他功能:

1.

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

运算结果:

  1. False True True
  2.  
  3. Process finished with exit code 0

2.

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

运算结果:

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

运算结果:

  1. True
  2.  
  3. Process finished with exit code 0

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

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

运算结果:

  1. False
  2.  
  3. Process finished with exit code 0

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

  1. test = 'sjalfa jafaaf'
  2. a1 = test.istitle()
  3. print(a1)

运算结果:

  1. False
  2.  
  3. Process finished with exit code 0

5.变成标题

  1. test = 'sjalfa jafaaf'
  2. a1 = test.istitle()
  3. a2 = test.title()
  4. print(a1)
  5. print(a2)

运算结果:

  1. False
  2. Sjalfa Jafaaf
  3.  
  4. Process finished with exit code 0

6.

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

运算结果:

  1. 你好啊猪头
  2.  
  3. Process finished with exit code 0

7.填充

  1. test = 'abcd'
  2. a = test.ljust(20,'*')
  3. a1 = test.center(20,'中')
  4. print(a)
  5. print(a1)

运算结果:

  1. abcd****************
  2. 中中中中中中中中abcd中中中中中中中中
  3.  
  4. Process finished with exit code 0

8.只用00填充

  1. test = 'abcd'
  2. a = test.zfill(20)
  3.  
  4. print(a)

运算结果:

  1. 0000000000000000abcd
  2.  
  3. Process finished with exit code 0

9.

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

运算结果:

  1. False abcd
  2.  
  3. Process finished with exit code 0

10.

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

运算结果:

  1. False ABCD
  2.  
  3. Process finished with exit code 0

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

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

12.移除指定字符串

  1. test = 'abcd'
  2. a = test.lstrip("a")
  3.  
  4. print(a)

运算结果:

  1. bcd
  2.  
  3. Process finished with exit code 0

13.分割

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

运算结果:

  1. ('lo', 'v', 'esdcvvf')
  2. ('lovesdcv', 'v', 'f')
  3. ['lo', 'esdc', 'vf']
  4. ['lovesdcvvf']
  5.  
  6. Process finished with exit code 0

14.

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

运算结果:

  1. ['adfsdf\n', 'safafsad\n', 'dsaf']
  2.  
  3. Process finished with exit code 0

15.

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

运算结果:

  1. True
  2. False
  3.  
  4. Process finished with exit code 0

16.大小写转换

  1. test = 'abc'
  2. a = test.swapcase()
  3. print(a)

运算结果:

  1. ABC
  2.  
  3. 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. 牛客训练21674——牛牛与LCM

    Problem 链接:https://ac.nowcoder.com/acm/problem/21674 来源:牛客网 牛牛最近在学习初等数论,他的数学老师给他出了一道题,他觉得太简单了, 懒得做,于 ...

  2. 超轻量级虚拟终端sakura和tilda

    一.安装: manjaro:pacman -S sakura ubunt:sudo apt install sakura 小当然是他的最大优点了,虽小但是功能挺全 可以同时打开好多个终端,termin ...

  3. 将页面中所有的checkbox设成单选得

    $(function () { var allBox = $(":checkbox"); allBox.click(function () { allBox.removeAttr( ...

  4. synchronized的原理与使用

    理论层面: 内置锁与互斥锁 修饰普通方法.修饰静态方法.修饰代码块 demo如下: package com.roocon.thread.t3; public class Sequence { priv ...

  5. Beta冲刺(2/4)

    队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11990570.html 作业博客 : https://edu.cnblogs.com/campus/ ...

  6. TynSerial基本数据类型序列(还原)

    TynSerial基本数据类型序列(还原) procedure TForm1.ToolButton17Click(Sender: TObject); var serial: TynSerial; be ...

  7. routine的加载

    // Hearthbuddy.Windows.MainWindow // Token: 0x06000245 RID: 581 RVA: 0x0008C318 File Offset: 0x0008A ...

  8. sql 从服务器取消主从复制

    mysql>change master to master_host='' mysql>stop slave;reset slave;

  9. Android高频单词

    Display 显示 Camera 照相机 Bluetooth 蓝牙 Flash Memory 闪存 Audio 音频 Management 管理 SurFace 界面 Media 多媒体 Frame ...

  10. fileBeat的简单使用

    Beat的简单使用 Filebeat配置 Output 常见日志格式封装 简单使用filebeat格式化nginx日志 Filebeat的配置: # 修改filebeat.yml # vim file ...