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 ...
随机推荐
- apose和spire操作word
Apose public void doSaveAsword(Dictionary<string,string> dict) { //--------------------------- ...
- ubuntu下安装Visual Studio Code
环境准备 先安装一般umake没有问题 sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt-get update sudo ...
- 微信内分享第三方H5链接无法使用内置浏览器打开的解决方案
很多朋友在微信内想分享转发H5链接的时候都会很容易碰到H5链接在微信内无法打开或在微信内无法打开app下载页的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢, ...
- Netty的基本使用
Gradle 的优点 原文:https://blog.csdn.net/achenyuan/article/details/80682288 1. 按约定声明构建和建设: 2. 强大的支持多工程的构 ...
- Java 静态内部类的加载时机
参考文章:[https://www.cnblogs.com/maohuidong/p/7843807.html] 前言: 在看单例模式的时候,在网上找帖子看见其中有一种(IoDH) 实现单例的方式,其 ...
- 二、Redis安装
一.下载Redis: 下载地址:https://github.com/MSOpenTech/redis/releases. 由于redis并不支持window系统,而window版本的redis的是由 ...
- SpringBoot配置MySql数据库和Druid连接池
1.pom文件增加相关依赖 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connec ...
- git只追踪特定类型的文件
比如我只关心所有office文档并排除掉~开头的辅助文件: * !*/ !*.docx !*.doc !*.xlsx ~*
- PAT 甲级真题题解(1-62)
准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format 模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...
- APP 后台学习笔记
1.APP后台功能: 远程存储数据.消息中转 2.架构是业务驱动,可能随着开发进程而变化,没有最完美架构 3.架构不要满足追求技术新奇酷炫,而是结合具体业务使用合适的技术,否则会给运维带来很多不必要的 ...