python学习--13 基本数据类型 2
接上次补充:
- 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的更多相关文章
- Python学习笔记 - day3 - 数据类型及运算符
Python的数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同 ...
- 记录我的 python 学习历程-Day03 数据类型 str切片 for循环
一.啥是数据类型 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能呀,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,"汉"是文字,否则它是分 ...
- python学习第九天数据类型列表创建,查找操作方法
数据类型中列表是整个python最常用的数据类型,列表最常用的方法就是创建,增删改查,切片,循环以及排序等系列操作,任何操作都离不开增删改查操作,这样很容记住操作方法 1,列表的创建 list=[] ...
- Python学习-字符编码, 数据类型
本篇主要内容: 字符编码 Python中的数据类型有哪些 类型的一些常用操作及方法 一.字符编码 编码解释的大部分内容摘自廖雪峰老师教程中的讲解,点击跳转. 简单介绍: 我们知道计算机只能处理数字,如 ...
- python学习03-数据类型
一.基本数据类型--数字 布尔型 bool型只有两个值:True和False 之所以将bool值归类为数字,是因为我们也习惯用1表示True,0表示False. 以下是布尔值是False的各种情况: ...
- Python学习手册之数据类型
在上一篇文章中,我们介绍了 Python 的异常和文件,现在我们介绍 Python 中的数据类型. 查看上一篇文章请点击:https://www.cnblogs.com/dustman/p/99799 ...
- python学习笔记(数据类型)
python数据类型: int 类型 float 小数类型 string 字符串 布尔类型 a = True b = False 1.列表,也称数组或list或array.它的表达方式通过下标或索引或 ...
- python学习道路(day2note)(数据类型,运算符,字符串,列表)
一,数据类型 1.1数字 数字分为int(整型),long(长整型),float(浮点型) 1.1.1 int整型的取值范围为 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31- ...
- python学习笔记二 数据类型(基础篇)
Python基础 对于Python,一切事物都是对象,对象基于类创建 不同类型的类可以创造出字符串,数字,列表这样的对象,比如"koka".24.['北京', '上 ...
随机推荐
- 牛客训练21674——牛牛与LCM
Problem 链接:https://ac.nowcoder.com/acm/problem/21674 来源:牛客网 牛牛最近在学习初等数论,他的数学老师给他出了一道题,他觉得太简单了, 懒得做,于 ...
- 超轻量级虚拟终端sakura和tilda
一.安装: manjaro:pacman -S sakura ubunt:sudo apt install sakura 小当然是他的最大优点了,虽小但是功能挺全 可以同时打开好多个终端,termin ...
- 将页面中所有的checkbox设成单选得
$(function () { var allBox = $(":checkbox"); allBox.click(function () { allBox.removeAttr( ...
- synchronized的原理与使用
理论层面: 内置锁与互斥锁 修饰普通方法.修饰静态方法.修饰代码块 demo如下: package com.roocon.thread.t3; public class Sequence { priv ...
- Beta冲刺(2/4)
队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11990570.html 作业博客 : https://edu.cnblogs.com/campus/ ...
- TynSerial基本数据类型序列(还原)
TynSerial基本数据类型序列(还原) procedure TForm1.ToolButton17Click(Sender: TObject); var serial: TynSerial; be ...
- routine的加载
// Hearthbuddy.Windows.MainWindow // Token: 0x06000245 RID: 581 RVA: 0x0008C318 File Offset: 0x0008A ...
- sql 从服务器取消主从复制
mysql>change master to master_host='' mysql>stop slave;reset slave;
- Android高频单词
Display 显示 Camera 照相机 Bluetooth 蓝牙 Flash Memory 闪存 Audio 音频 Management 管理 SurFace 界面 Media 多媒体 Frame ...
- fileBeat的简单使用
Beat的简单使用 Filebeat配置 Output 常见日志格式封装 简单使用filebeat格式化nginx日志 Filebeat的配置: # 修改filebeat.yml # vim file ...