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-字符串的处理的更多相关文章

  1. 关于python字符串连接的操作

    python字符串连接的N种方式 注:本文转自http://www.cnblogs.com/dream397/p/3925436.html 这是一篇不错的文章 故转 python中有很多字符串连接方式 ...

  2. 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 ...

  3. Python 字符串

    Python访问字符串中的值 Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. Python访问子字符串,可以使用方括号来截取字符串,如下实例: #!/usr/bin/py ...

  4. python字符串方法的简单使用

    学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...

  5. python字符串基础知识

    1.python字符串可以用"aaa",'aaa',"""aaa""这三种方式来表示 2.python中的转义字符串为" ...

  6. Python 字符串格式化

    Python 字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存 一 ...

  7. Python 字符串操作

    Python 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) 去空格及特殊符号 s.strip() .lstrip() .rstrip(',') 复制字符 ...

  8. 【C++实现python字符串函数库】strip、lstrip、rstrip方法

    [C++实现python字符串函数库]strip.lstrip.rstrip方法 这三个方法用于删除字符串首尾处指定的字符,默认删除空白符(包括'\n', '\r', '\t', ' '). s.st ...

  9. 【C++实现python字符串函数库】二:字符串匹配函数startswith与endswith

    [C++实现python字符串函数库]字符串匹配函数startswith与endswith 这两个函数用于匹配字符串的开头或末尾,判断是否包含另一个字符串,它们返回bool值.startswith() ...

  10. 【C++实现python字符串函数库】一:分割函数:split、rsplit

    [C++实现python字符串函数库]split()与rsplit()方法 前言 本系列文章将介绍python提供的字符串函数,并尝试使用C++来实现这些函数.这些C++函数在这里做单独的分析,最后我 ...

随机推荐

  1. Oracle分组函数之CUBE

    功能介绍: 首先是进行无字段的聚合,然后依次对每个字段进行聚合 创建表: 插入测试数据: ROLLUP: Select t.classid,t.studentname,Sum(t.score) Fro ...

  2. Web上传文件的三种解决方案

    第一点:Java代码实现文件上传 FormFile file = manform.getFile(); String newfileName = null; String newpathname =  ...

  3. [luogu]P1133 教主的花园[DP]

    [luogu]P1133 教主的花园 ——!x^n+y^n=z^n 题目描述 教主有着一个环形的花园,他想在花园周围均匀地种上n棵树,但是教主花园的土壤很特别,每个位置适合种的树都不一样,一些树可能会 ...

  4. sts创建maven项目 引入spring,报错

    症状: Missing artifact org.springframework:spring-core:jar:5.0.0.RC3 原因: 在引入之前没有设置spring版本号 和spring ur ...

  5. Step2 - How to: Implement a Windows Communication Foundation Service Contract

    This is the second of six tasks required to create a basic Windows Communication Foundation (WCF) se ...

  6. 【The type javax.servlet.http.HttpServletRequest cannot be resolved】解决方案

    是缺少serverlet的引用库,解决如下 1.工程右键-properties->java build path 2.在java build path的libraries tab页中选择Add ...

  7. Selenium WebDriver高级应用

    WebDriver高级应用 public class Demo4 { WebDriver driver; // @BeforeMethod:在每个测试方法开始运行前执行 @BeforeMethod p ...

  8. Linear Regression and Gradient Descent

    随着所学算法的增多,加之使用次数的增多,不时对之前所学的算法有新的理解.这篇博文是在2018年4月17日再次编辑,将之前的3篇博文合并为一篇. 1.Problem and Loss Function ...

  9. Fira Code,可以让不等号!=直接显示出来的字体

    今天看B站某直播间有人写代码C#里一堆不等号直接显示,感觉很神奇,以为是插件还是什么新语法,托人问了下原来是Fira Code字体 https://github.com/tonsky/FiraCode ...

  10. git团队协作代码提交步骤

    我们公司由五个人同时开发一个项目,大佬建好仓库后叫我们统一提交到dev这个分支,我的分支是hardy,你们只要将这两个值改成你们团队协作中使用的分支即可.代码如下: git add . git com ...