python-字符串的处理
s1 = '###12314##231###'
print(s1.split('#')) #split,从左往右遇见# 就拆分一次['', '', '', '12314', '', '231', '', '', ''] print(s1.strip('#')) #strip 去除两侧的 # 12314##231
print(s1.lstrip('#')) #lstrip 去除左侧的 12314##231###
print(s1.rstrip('#')) #rstrip 去除右侧的 print(s1.replace('#','')) #replace是代替的意思,把所有的#都换成空 12314231
print(s1.replace('','')) s2 = 'abcABC'
print(s2.lower()) #lower() 全变成小写
print(s2.upper())
print(s2.endswith('C'))
print(s2.startswith('A'))
print(s2.title()) #首字母大写Abcabc
print(s2.count('a')) l1 = list('')
print(','.join(l1)) #以,将l1拼接在一起成字符串6,6,6
print(':'.join(s2)) #a:b:c:A:B:C
import os
path = os.getcwd() #获取文件夹路径(不包含文件名)
print(path)
print(os.path.realpath(__file__)) #获取该文件的路径F:\asus\auto_file\unittest_html\list1.py
print(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-字符串的处理的更多相关文章
- 关于python字符串连接的操作
python字符串连接的N种方式 注:本文转自http://www.cnblogs.com/dream397/p/3925436.html 这是一篇不错的文章 故转 python中有很多字符串连接方式 ...
- StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?
StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...
- Python 字符串
Python访问字符串中的值 Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. Python访问子字符串,可以使用方括号来截取字符串,如下实例: #!/usr/bin/py ...
- python字符串方法的简单使用
学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...
- python字符串基础知识
1.python字符串可以用"aaa",'aaa',"""aaa""这三种方式来表示 2.python中的转义字符串为" ...
- Python 字符串格式化
Python 字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存 一 ...
- Python 字符串操作
Python 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) 去空格及特殊符号 s.strip() .lstrip() .rstrip(',') 复制字符 ...
- 【C++实现python字符串函数库】strip、lstrip、rstrip方法
[C++实现python字符串函数库]strip.lstrip.rstrip方法 这三个方法用于删除字符串首尾处指定的字符,默认删除空白符(包括'\n', '\r', '\t', ' '). s.st ...
- 【C++实现python字符串函数库】二:字符串匹配函数startswith与endswith
[C++实现python字符串函数库]字符串匹配函数startswith与endswith 这两个函数用于匹配字符串的开头或末尾,判断是否包含另一个字符串,它们返回bool值.startswith() ...
- 【C++实现python字符串函数库】一:分割函数:split、rsplit
[C++实现python字符串函数库]split()与rsplit()方法 前言 本系列文章将介绍python提供的字符串函数,并尝试使用C++来实现这些函数.这些C++函数在这里做单独的分析,最后我 ...
随机推荐
- mysql版本
$ mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 4791 ...
- sublime text 3 Package Control无法下载插件
Package Control无法下载插件,发现是因为被墙了. ubuntu18.04 下使用privoxy设置全局参见:https://www.cnblogs.com/linjunfu/p/1101 ...
- VBA在Excel中的应用(三)
目录 Chart Export Chart Format Chart Lengend Chart Protect Chart Title Chart Chart Export 1. 将Exce ...
- How to pass values across the pages in ASP.net without using Session
https://stackoverflow.com/questions/14956027/how-to-pass-values-across-the-pages-in-asp-net-without- ...
- scrapy xpath xpath('---').xpath('string(.)') 提取子元素全部文本
product.xpath("div//div[@class='a-row a-spacing-mini'][1]/div[2]").xpath('string(.)')
- 杂项-SAP:SAP (服务访问点(Service Accessing point))
ylbtech-杂项-SAP:SAP (服务访问点(Service Accessing point)) 1.返回顶部 1. SAP,是Service Accessing point的缩写,意思是服务访 ...
- selenium python 报错“ unable to find binary in default location”
selenium python 报错如下: raise exception_class(message, screen, stacktrace)selenium.common.exceptions.W ...
- [Codeforces722E] Research Rover (dp+组合数学)
[Codeforces722E] Research Rover (dp+组合数学) 题面 给出一个N*M的方格阵,从(1,1)出发,到(N,M)结束,从(x,y)只能走到(x+1,y)或(x,y+1) ...
- hdu6311 Cover (欧拉路径输出)
hdu6311Cover 题目传送门 题意:有最少用多少条边不重复的路径可以覆盖一个张无向图. 分析:对于一个连通块(单个点除外),如果奇度数点个数为 k,那么至少需要max{k/2,1} 条路径. ...
- 浅谈随机数发生器(C语言)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/svitter/article/details/30971395 本文出自:点击打开链接 本来在做数据 ...