python-字符串方法(40)

news/2024/8/26 15:12:04
>>> py_str = 'hello word!'
>>> py_str.capitalize()    #把字符串的第一个字符大写
'Hello word!'
>>> py_str.title() #每个单词的第一个字符大写
'Hello Word!'
>>> py_str.center(50)  #返回一个原字符串居中,并使用空格填充至长度50的新字符串
'                   hello word!                    '
>>> py_str.center(50,'#')  #用#填充
'###################hello word!####################'
>>> py_str.ljust(50,'*')   #左对齐,*填充
'hello word!***************************************'
>>> py_str.rjust(50,'*')   #右对齐,*填充
'***************************************hello word!'
>>> py_str.count('l')  #统计l出现的次数
2
>>> py_str.count('lo')
1
>>> py_str.endswith('!')   #以!结尾?
True
>>> py_str.endswith('d!')
True
>>> py_str.startswith('a') #以a开头?
False
>>> py_str.islower()   #字母全部小写?
True
>>> py_str.isupper()   #字母全部是大写?
False
>>> 'Hao123'.isdigit() #全部是数字?
False
>>> 'Hao123'.isalnum() #全部是字母数字?
True
>>> '    hello\t    '.strip()  #去除两端的的空白
'hello'
>>> '    hello\t    '.lstrip() #去除左空白
'hello\t    '
>>> '    hello\t    '.rstrip() #去除右空白
'    hello'
>>> 'how are you?'.split() #split(),分割,分片,默认以空格为分隔符
['how', 'are', 'you?']
>>> 'hello.tar.gz'.split('.')
['hello', 'tar', 'gz']
>>> '.'.join(['hello','tar','gz'])
'hello.tar.gz'
>>> '_'.join(['hello','tar','gz'])
'hello_tar_gz'

http://www.niftyadmin.cn/n/3433349.html

相关文章

STP两种BPDU

BPDU分两种:配置信息BPDUTCN拓扑变更BPDU传递方向:配置信息BPDU从根桥的指定口向下传递,不会从根口发出TCN从根口向根桥传递,直到根桥收到,再发配置信息到各个交换机。转载于:https://blog.51cto.com/windball/2060841…

#pragma comment(lib, WSock32.lib)

#pragma 的使用 尽管 C 和 C 都已经有标准,但是几乎每个编译器 (广义,包含连接器等) 扩展一些 C/C 关键字。 合理地应用这些关键字,有时候能使我们的工作非常方便。下面随便说说 Visual C 中 #pragma 指示符的使用。 一、用#pragma导出DL…

python-shutil模块常用方法(42)

>>> import shutil >>> with open(/etc/passwd,rb) as sfobj: ... with open(/tmp/mima.txt,wb) as dfobj: ... shutil.copyfileobj(sfobj,dfobj) #拷贝文件对象 >>> shutil.copyfile(/etc/passwd,/tmp/mima2.txt) #拷贝&…

Node.js 19 正式发布,新特性一览

原文地址:Node.js 19 正式发布,新特性一览 Node.js 19 在19日正式发布了,此次更新包括将 V8 JavaScript 引擎更新到 10.7,以及默认启用 HTTP (s)/1.1 KeepAlive。 Node.js 18 在本月晚些时候将进入长期支持(LTS)&…

map和reduce 个数的设定

2019独角兽企业重金招聘Python工程师标准>>> 原文链接:http://blog.csdn.net/aaa1117a8w5s6d/article/details/33781319 map task的数量即mapred.map.tasks的参数值,用户不能直接设置这个参数。Input Split的大小,决定了一个Job拥…

codeforces 582A GCD Table

题意简述: 给定一个长度为$n$的序列 将这个序列里的数两两求$gcd$得到$n^2$个数 将这$n^2$个数打乱顺序给出 求原序列的一种可能的情况 -----------------------------------------------------------------------------------------------------------------------…

python-生成文本文件(43)

import osdef get_fname():while True:fname input(filename: )if not os.path.exists(fname): #os.path.exists(),查看文件是否存在breakprint(%s already exists. Try again % fname)return fnamedef get_content():content []print(输入数据,输入end结束)whi…

IOS 自定义的UITableViewCell实现UITableView

出错:this class is not key value coding-compliant for the key 1.检查各种连线,多连线,少连线都会导致错误 2.检查自定义cell的class: 3.检查cell的files owner的class: 4.自定义cell的Identification必须和control…