python3字符串
Python3 字符串
Python字符串运算符
|
+ |
字符串连接 |
a + b 输出结果: HelloPython |
|
* |
重复输出字符串 |
a*2 输出结果:HelloHello |
|
[] |
通过索引获取字符串中字符 |
a[1] 输出结果 e |
|
[ : ] |
截取字符串中的一部分,取到截止点的前一个 |
a[1:4] 输出结果 ell |
|
in |
成员运算符 - 如果字符串中包含给定的字符返回 True |
H in a 输出结果 1 |
|
not in |
成员运算符 - 如果字符串中不包含给定的字符返回 True |
M not in a 输出结果 1 |
|
r/R |
原始字符串 - 原始字符串:所有的字符串都是直接按照字面的意思来使用,没有转义特殊或不能打印的字符。 原始字符串除在字符串的第一个引号前加上字母"r"(可以大小写)以外,与普通字符串有着几乎完全相同的语法。 |
print r'\n' prints \n 和 print R'\n' prints \n |
|
% |
格式字符串 |
请看下一节内容。 |
|
[ : : ] |
以跳固定步数的方式,截取字符串中的一部分 |
a[0:6:2] 输出结果:Hlo |
Python 的字符串内建函数
|
1 |
capitalize() |
|
2 |
center(width, fillchar) |
|
3 |
count(str, beg= 0,end=len(string)) |
|
4 |
bytes.decode(encoding="utf-8", |
|
5 |
encode(encoding='UTF-8',errors='strict') |
|
6 |
endswith(suffix, beg=0, end=len(string)) |
|
7 |
expandtabs(tabsize=8) |
|
8 |
find(str, beg=0 end=len(string)) |
|
9 |
index(str, beg=0, end=len(string)) |
|
10 |
isalnum() |
|
11 |
isalpha() |
|
12 |
isdigit() |
|
13 |
islower() |
|
14 |
isnumeric() |
|
15 |
isspace() |
|
16 |
istitle() |
|
17 |
isupper() |
|
18 |
join(seq) |
|
19 |
len(string) |
|
20 |
ljust(width[, fillchar]) |
|
21 |
lower() |
|
22 |
lstrip() |
|
23 |
maketrans() |
|
24 |
max(str) |
|
25 |
min(str) |
|
26 |
replace(old, new [, max]) |
|
27 |
rfind(str, beg=0,end=len(string)) |
|
28 |
rindex( str, beg=0, end=len(string)) |
|
29 |
rjust(width,[, fillchar]) |
|
30 |
rstrip() |
|
31 |
split(str="", num=string.count(str)) |
|
32 |
splitlines([keepends]) |
|
33 |
startswith(str, beg=0,end=len(string)) |
|
34 |
strip([chars]) |
|
35 |
swapcase() |
|
36 |
title() |
|
37 |
translate(table, deletechars="") |
|
38 |
upper() |
|
39 |
zfill (width) |
|
40 |
isdecimal() |
python3字符串的更多相关文章
- [转]python3字符串与文本处理
转自:python3字符串与文本处理 阅读目录 1.针对任意多的分隔符拆分字符串 2.在字符串的开头或结尾处做文本匹配 3.利用shell通配符做字符串匹配 4.文本模式的匹配和查找 5.查找和替换文 ...
- python3字符串操作
python3字符串操作 x = 'abc' y = 'defgh' print(x + y) #x+y print(x * ) #x*n print(x[]) #x[i] print(y[:-]) ...
- 【2】python3字符串的比较(辨析is与==的区别)
PYTHON3基本数据类型(二.字符串) Python3字符串 ①字符串比较 1.比较字符串是否相同: ==:使用==来比较两个字符串内的value值是否相同 is:比较两个字符串的id值. 2.字符 ...
- python系列四:Python3字符串
#!/usr/bin/python #Python3 字符串#可以截取字符串的一部分并与其他字段拼接var1 = 'Hello World!'print ("已更新字符串 : ", ...
- python3 字符串属性(一)
python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...
- (十四)Python3 字符串格式化
Python3 字符串格式化 字符串的格式化方法分为两种,分别为占位符(%)和format方式.占位符方式在Python2.x中用的比较广泛,随着Python3.x的使用越来越广,format方式使用 ...
- Python3字符串 详解
Python3 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. Python 访问字符串中的值 P ...
- [No000078]Python3 字符串操作
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...
- python3 字符串操作相关函数
整理自python基础|菜鸟教程 感谢菜鸟教程提供的优质资源! 1.capitalize() 将字符串的第一个字符转换为大写 实例 以下实例展示了capitalize()方法的实例: #!/usr/b ...
随机推荐
- Net包管理NuGet(3)搭建私服及引用私服的包
1,打开vs创建项目(ASP.NET WEB空项目)假设命名为MyNuGet 空项目解决方案如图 2,右键引用>管理NuGet程序包>切到浏览搜索NuGet.Server然后安装(3.1. ...
- NodeJs之定时器与队列
NodeJs之定时器与队列 一,介绍与需求 1.1,介绍 定时任务(node-schedule),是针对Node.js的一种灵活的cron-like和not-cron-like作业调度程序.它允许您使 ...
- stm32串口接收发送数据处理
/************************************************************* Function Name : Uart1_Send_Byte* Desc ...
- springmvc的前端控制器
<servlet> <servlet-name>xxx</servlet-name> <servlet-class>org.springframewor ...
- PHP知识点记录
笔记源自---PHP必须知道的300个问题 一.提高编程效率 1.echo中字符串用单引号包含起来会比用双引号快. 2.$row['id']的速度要比$row[id]快很多. 3.echo比print ...
- python 元组用法
tup1 = ('physics', 'chemistry', 1997, 2000) 元组中的元素值是不允许修改的 序号 方法及描述 1 cmp(tuple1, tuple2)比较两个元组元素. 2 ...
- did not finish being created even after we waited 189 seconds or 61 attempts. And its status is downloading
did not finish being created even after we waited 189 seconds or 61 attempts. And its status is down ...
- 「NOI2013」小 Q 的修炼 解题报告
「NOI2013」小 Q 的修炼 第一次完整的做出一个提答,花了半个晚上+一个上午+半个下午 总体来说太慢了 对于此题,我认为的难点是观察数据并猜测性质和读入操作 我隔一会就思考这个sb字符串读起来怎 ...
- Codeforces Round #554 (Div. 2) C. Neko does Maths(数学+GCD)
传送门 题意: 给出两个整数a,b: 求解使得LCM(a+k,b+k)最小的k,如果有多个k使得LCM()最小,输出最小的k: 思路: 刚开始推了好半天公式,一顿xjb乱操作: 后来,看了一下题解,看 ...
- yarn安装使用
npm install yarn -g // 到指定文件夹 yarn init // 生成package.json文件 yarn init报错 Can't answer a question unle ...