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++函数在这里做单独的分析,最后我 ...
随机推荐
- Cenos7下nginx+mysql+php环境的搭建
首先更新系统软件 1 $ yum update 第一步:安装nginx 1.安装nginx源 1 $ yum localinstall http://nginx.org/packages/centos ...
- sql2000如何完美压缩.mdf文件
--收缩数据库 dbcc shrinkdatabase('test_db') , ) --数据文件mdf , ) --日志文件ldf ) --更新
- 【2019 Multi-University Training Contest 7】
01:https://www.cnblogs.com/myx12345/p/11653845.html 02: 03: 04: 05: 06:https://www.cnblogs.com/myx12 ...
- MS4W安装教程
简介 欢迎使用MS4W,这是由Gateway Geomatics开发的快速简便的安装程序,用于为Windows及其附带应用程序(如Geomoose.MapBender.Openlayers等)设置Ma ...
- MapServer教程2
第二章 Tutorial 教程 MapServer Tutorial MapServer教程 Tutorial background 教程背景 Section 1: Static Maps and t ...
- 获取系统的documents路径
获取路径 https://superuser.com/questions/1132288/windows-command-prompt-get-relocated-users-documents-fo ...
- js/jq 小功能函数
1.点击复制内容到剪贴板 function copyToClip(str) { var save = function(e) { e.clipboardData.setData('text/plain ...
- P2258子矩阵
传送 一道看起来就很暴力的题. 这道题不仅暴力,还要用正确的姿势打开暴力. 因为子矩阵的参数有两个,一个行一个列(废话) 我们一次枚举两个参数很容易乱对不对?所以我们先枚举行,再枚举列 枚举完行,列, ...
- day27—JavaScript实现定时器及其应用案例
转行学开发,代码100天——2018-04-12 JavaScript中定时器有两种,分别是setInterval和setTimeout;其用法如下: 开启: setTimeout("fun ...
- spring cloud网关gateway
spring gateway使用基于netty异步io,第二代网关:zuul 1使用servlet 3,第一代网关,每个请求一个线程,同步Servlet,多线程阻塞模型.而spring貌似不想在支持z ...