python字符串的方法

############7个基本方法############

1:join

 def join(self, ab=None, pq=None, rs=None): # real signature unknown; restored from __doc__
"""
Concatenate any number of strings. The string whose method is called is inserted in between each given string.
The result is returned as a new string. Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
"""
可以向字符串插入 标识符 标点 字母等连接
test=("qweqweqw")
v="_".join(test)
print(v) q_w_e_q_w_e_q_w test=(['as','df','as'])
v="_".join(test)
print(v) as_df_as

  

2:split(正则)

 split(self, *args, **kwargs): # real signature unknown
"""
Return a list of the words in the string, using sep as the delimiter string. sep
The delimiter according which to split the string.
None (the default value) means split according to any whitespace,
and discard empty strings from the result.
maxsplit
Maximum number of splits to do.
-1 (the default value) means no limit.
"""
全分割 从第一个逐一扫描字符串寻找所选字符 从字符串中找到该字符位置开始分割 (所选字符消失)
test=("asdfasdfasdfsadfsdf")
v=test.split("f")
print(v) ['asd', 'asd', 'asd', 'sad', 'sd', ''] test=("asdfasdfasdf")
v=test.split("s",2,)
print(v) ['a', 'dfa', 'dfasdf']

  


3:find

find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation. Return -1 on failure.
"""
return 0
从左向右查找所定义的字符 显示首个该字符的索引(下标);find(字符,开始索引,结束索引)
test=("asdfasdfasdfsadfsdf")
v=test.find("f")
print(v) 3 test=("asdfasdfasdfsadfsdf")
v=test.find("f",5,15)
print(v) 7

  

4:strip

strip(self, *args, **kwargs): # real signature unknown
"""
Return a copy of the string with leading and trailing whitespace remove. If chars is given and not None, remove characters in chars instead.
"""
清除字符串两边的空格
test=("  asdfasdfas   dfsadfsdf   ")
v=test.strip()
print(v) asdfasdfas dfsadfsdf

  

5:upper

upper(self, *args, **kwargs): # real signature unknown
""" Return a copy of the string converted to uppercase. """
字符串全大写
test=("asdfasdfasdfsadfsdf")
v=test.upper()
print(v) ASDFASDFASDFSADFSDF

  

6:lower

lower(self, *args, **kwargs): # real signature unknown
""" Return a copy of the string converted to lowercase. """
pass
字符串全小写
test=("ASDFASDFASDFSADFSDF")
v=test.lower()
print(v) asdfasdfasdfsadfsdf

  

7:replace

replace(self, *args, **kwargs): # real signature unknown
"""
Return a copy with all occurrences of substring old replaced by new. count
Maximum number of occurrences to replace.
-1 (the default value) means replace all occurrences. If the optional argument count is given, only the first count occurrences are
replaced.
"""
替换所选字符 replace(“文本内的字符”,“想要替换文本的字符”,“替换的数量”)
test=("ASDFASDFASDFSADFSDF")
v=test.replace("ASD","aaa",1)
print(v) aaaFASDFASDFSADFSDF test=("ASDFASDFASDFSADFSDF")
v=test.replace("ASD","aaa")
print(v) aaaFaaaFaaaFSADFSDF

  

python字符串的方法的更多相关文章

  1. python字符串replace()方法

    python字符串replace()方法 >>> help(str.replace)Help on method_descriptor:replace(...)    S.repla ...

  2. 7. python 字符串格式化方法(2)

    7. python 字符串格式化方法(2) 紧接着上一章节,这一章节我们聊聊怎样添加具体格式化 就是指定替换字段的大小.对齐方式和特定的类型编码,结构如下: {fieldname!conversion ...

  3. 7. python 字符串格式化方法(1)

    7. python 字符串格式化方法(1) 承接上一章节,我们这一节来说说字符串格式化的另一种方法,就是调用format() >>> template='{0},{1} and {2 ...

  4. python字符串格式化方法 format函数的使用

      python从2.6开始支持format,新的更加容易读懂的字符串格式化方法, 从原来的% 模式变成新的可读性更强的 花括号声明{}.用于渲染前的参数引用声明, 花括号里可以用数字代表引用参数的序 ...

  5. Python字符串解析方法汇总

    Python字符串方法解析 1.capitalize 将首字母大写,其余的变成小写 print('text'.capitalize()) print('tExt'.capitalize()) 结果: ...

  6. python字符串排序方法

    一般情况下,python中对一个字符串排序相当麻烦: 一.python中的字符串类型是不允许直接改变元素的.必须先把要排序的字符串放在容器里,如list. 二.python中的list容器的sort( ...

  7. python字符串处理方法

    一.combine & duplicate 字符串结合和复制 字符和字符串可以用来相加来组合成一个字符串输出: 字符或字符串复制输出. 二.Extract &Slice 字符串提取和切 ...

  8. python字符串连接方法效率比较

    方法1:直接通过加号(+)操作符连接 1 website = 'python' + 'tab' + '.com' 方法2:join方法 1 2 listStr = ['python', 'tab',  ...

  9. 【Python基础教程】三种常用、效率最高的Python字符串拼接方法

    python字符串连接的方法,一般有以下三种: **方法1:**直接通过加号(+)操作符连接website=& 39;python& 39;+& 39;tab& 39; ...

随机推荐

  1. bat 传递参数

    调用bat时,传递参数有个小问题,记录一下. 1.问题描述: 传递参数时,接收的值不对.传递了“1,2,3”,接收时,只剩下1.后面的没有了. 解决: 原因是bat取参时,语法弄错了. Syntax ...

  2. Temporary failure in name resolutionf的解决方法

    Linux有时还蛮烦的这个不能用那个不能用,只能多折腾了. 今天又是,ping z.cn的时候直接报错 Temporary failure in name resolutionf 这个一般都知道是DN ...

  3. [工作积累] UE4 并行渲染的同步 - Sync between FParallelCommandListSet & FRHICommandListImmediate calls

    UE4 的渲染分为两个模式1.编辑器是同步绘制的 2.游戏里是FParallelCommandListSet并行派发的. mesh渲染也分两类,static mesh 使用TStaticMeshDra ...

  4. 安装ns2.34,802.11p的各种包的时候遇到问题

    安装教程:http://blog.sina.com.cn/s/blog_6735526a0102w1zs.html 802.11p补丁包:https://download.csdn.net/downl ...

  5. Mybatis逆向工程的配置

    源码github下载地址:https://github.com/wcyong/mybatisGeneratorCustom.git 参考文章:https://www.cnblogs.com/whgk/ ...

  6. Java技术开发程序员如果在2019年立足

    2019年的互联网环境相对以往来说要更复杂一些,互联网领域也正在经历从消费互联网向产业互联网转型的阵痛期.其实不少公司从2018年开始已经在陆续进行结构化调整,这些调整中的重要内容就是岗位调整,而岗位 ...

  7. Zuul网关总结

    Zuul是Netflix开源的网关服务(gateway service)(https://github.com/Netflix/zuul),提供动态路由.监控.弹性.安全性等功能.最近在公司的项目中用 ...

  8. 18.13 Uboot分析与移植

    18.13.1 使用JLink烧写Nor Flash JLink只支持烧写NOR Flash,不支持烧写Nand Flash. 1.准备工作:JLink的USB口接到电脑上,JLink的JTAG口用排 ...

  9. 如何长期试用Beyond Compare 4

    打开Beyond Compare 4,发现已经过了试用期   我们可以点击立即购买,购买相关的Beyond Compare 4产品,如果你已经有密钥了,可以选择使用密钥   如果还想继续试用,则找到自 ...

  10. pascalcontext-fcn全卷积网络结构理解

    一.说明 fcn的开源代码:https://github.com/shelhamer/fcn.berkeleyvision.org 论文地址:fully convolutional networks ...