python-字符串的处理,,s1 = ‘###1
python-字符串的处理,,s1 = ‘###1
s1 = ‘###12314##231###‘print(s1.split(‘#‘)) #split,从左往右遇见# 就拆分一次[‘‘, ‘‘, ‘‘, ‘12314‘, ‘‘, ‘231‘, ‘‘, ‘‘, ‘‘]print(s1.strip(‘#‘)) #strip 去除两侧的 # 12314##231print(s1.lstrip(‘#‘)) #lstrip 去除左侧的 12314##231###print(s1.rstrip(‘#‘)) #rstrip 去除右侧的print(s1.replace(‘#‘,‘‘)) #replace是代替的意思,把所有的#都换成空 12314231print(s1.replace(‘123‘,‘666‘))s2 = ‘abcABC‘print(s2.lower()) #lower() 全变成小写print(s2.upper())print(s2.endswith(‘C‘))print(s2.startswith(‘A‘))print(s2.title()) #首字母大写Abcabcprint(s2.count(‘a‘))l1 = list(‘666‘)print(‘,‘.join(l1)) #以,将l1拼接在一起成字符串6,6,6print(‘:‘.join(s2)) #a:b:c:A:B:Cimport ospath = os.getcwd() #获取文件夹路径(不包含文件名)print(path)print(os.path.realpath(__file__)) #获取该文件的路径F:\asus\auto_file\unittest_html\list1.pyprint(os.path.basename(os.path.realpath(__file__))) #获取文件名print(os.path.dirname(os.path.realpath(__file__))) #和os.getcwd()一样的,但是要传参数print(os.path.join(path,os.path.basename(os.path.realpath(__file__)))) #os.path.join()拼接路径
------------------------------------------
‘‘‘
需求是这样的,假如需要测一个输入框最大能输入250汉字,怎么来创造这250汉字
‘‘‘
import sys
import random
def fun(n):
i = 0
l = [‘我‘,‘你‘,‘她‘]
l1 = []
while i<int(n):
a = random.choice(l)
l1.append(a)
i+=1
s = ‘‘.join(l1)
print(s)
if __name__ == ‘__main__‘:
if len(sys.argv) == 2:
n = sys.argv[1]
fun(n)
python-字符串的处理
相关内容
- Pyton项目打包成exe文件,,Python项目打包
- Python读取文件编码解码问题,,用chardet检测
- python中的global,,https://bl
- python3.5+installer 将.py 打包成.exe,,(1)下载安装ins
- python判断命令执行成功,,if os.syst
- Python--字符串格式化,,1、字符串格式化pr
- python的re模块理解(re.compile、re.match、re.search),,imp
- Centos7下python3安装ipython,,一、通过压缩包安装i
- mnist的格式说明,以及在python3.x和python 2.x读取mnist数据
- Python可视化 | Seaborn5分钟入门(六)——heatmap热力图,,
评论关闭