Python字符串常用的方法——真心觉得比java,c好用
# Strings have many methods wo can use
rand_string=" life is a beautiful struggle "
print("去除左边空格:",rand_string.lstrip())
print("去除右边的空格:",rand_string.rstrip())
print("去除两边的空格:",rand_string.strip())
print()
rand_string=rand_string.strip()
print("首字符变为大写:",rand_string.capitalize())
print("全部字母变为大写:",rand_string.upper())
print("全部变为小写:",rand_string.lower())
print("**********列表**********")
stringList=["I","am","a","student"]
print("输出列表:"," ".join(stringList))
randList=rand_string.split()
print("输出字符串变为数组:")
for i in randList:
print(i)
print()
print("字符串有多少个if;",rand_string.count("if"))
print("字符串is的位置:",rand_string.find("is"))
print("我们把struggle变为journey:",rand_string.replace('struggle','journet'))
print("************对字符串数字进行判断*********")
letter="r"
num=""
space=" "
print("判断字符串是否为字符:",letter.isalpha())
print("判断字符串是否为字符或者数字:",letter.isalnum())
print("判断字符串是否为数字:",num.isdigit())
print("判断字符串是否为空格:",space.isspace())
Python字符串常用的方法——真心觉得比java,c好用的更多相关文章
- python字符串常用的方法解析
这是本人在学习python过程中总结的一些关于字符串的常用的方法. 文中引用了python3.5版本内置的帮助文档,大致进行翻译,并添加了几个小实验. isalnum S.isalnum() -> ...
- Python语言学习:字符串常用的方法
python字符串常用的方法 1. find( ):在字符串中搜索指定的值并返回它被找到的位置,如果没有找到,则返回-1 string.find(value,start,end) #value:必需, ...
- python字符串常用内置方法
python字符串常用内置方法 定义: 字符串是一个有序的字符的集合,用与存储和表示基本的文本信息. python中引号中间包含的就是字符串. # s1='hello world' # s2=&quo ...
- python字符串操作实方法大合集
python字符串操作实方法大合集,包括了几乎所有常用的python字符串操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下: #1.去空格及特殊符号 s.st ...
- python 字符串常用操作方法
python 字符串常用操作方法 python 字符串操作常用操作,如字符串的替换.删除.截取.赋值.连接.比较.查找.分割等 1.去除空格 str.strip():删除字符串两边的指定字符,括号的写 ...
- python3【基础】-字符串 常用的方法
字符串一个最重要的特性就是不可修改. name.capitalize() 首字母大写 name.casefold() 大写全部变小写 name.center(50,"-") 输出 ...
- Python—字符串常用函数
Python-字符串常用字符串 字符串是一种表示文本的数据类型,使用单引号和双引号及三引号表示 访问字符串中的值字符串的每个字符都对应一个下标,下标编号是从0开始 转义字符字符串的格式化输出切片常用函 ...
- python字符串常用操作方法
python字符串操作常用操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下. 1.去除空格str.strip():删除字符串两边的指定字符,括号的写入指定字符,默 ...
- Python 字符串格式化操作 - format方法
建议使用format()方法 字符串操作 对于 %, 官方以及给出这种格式化操作已经过时,在 Python 的未来版本中可能会消失. 在新代码中使用新的字符串格式.因此推荐大家使用format()来替 ...
随机推荐
- fsLayuiPlugin数据表格弹出form表单说明
fsLayuiPlugin 是一个基于layui的快速开发插件,支持数据表格增删改查操作,提供通用的组件,通过配置html实现数据请求,减少前端js重复开发的工作. GitHub下载 码云下载 测试环 ...
- The first one spawns an additional process forwarding requests to a series of workers (think about it as a form of shield, at the same level of apache or nginx), while the second one sets workers to n
Things to know (best practices and “issues”) READ IT !!! — uWSGI 2.0 documentationhttps://uwsgi-docs ...
- start开启服务的生命周期
* 完整生命周期:onCreate()-->onStartCommand()-->onDestroy() * 开启服务:onCreate()-->onStartCommand() * ...
- Build Telemetry for Distributed Services之OpenTracing简介
官网地址:https://opentracing.io/ What is Distributed Tracing? Who Uses Distributed Tracing? What is Open ...
- [Bayes] Maximum Likelihood estimates for text classification
Naïve Bayes Classifier. We will use, specifically, the Bernoulli-Dirichlet model for text classifica ...
- List 的删除
List 不要在循环中使用remove 删除.可以新加一个List ,把符合条件的元素加入到这个list 中,然后调用removeAll . 比如:(增强for 循环需要判断 list 是否是 nul ...
- 如何使用postman模拟https的post和get请求
下载postman The Collaboration Platform for API Development https://www.getpostman.com/ 按照api文档要求测试,下面以 ...
- C#进阶系列—WebApi
参考学习优秀博客地址:http://www.cnblogs.com/landeanfen/p/5177176.html
- 数据结构——关于任一二叉树n0=n2+1的证明
对于任一二叉树,若度为2的结点有n2个,则叶子结点数必为n2+1 证明: 假设该二叉树总共有n个结点(n=n0+n1+n2),则该二叉树总共会有n-1条边,度为2的结点会延伸出两条边, 同理,度为1的 ...
- poj1753 (高斯消元法求异或方程组)
题目链接:http://poj.org/problem?id=1753 题意:经典开关问题,和poj1222一样,进行两次高斯消元即可,只用初始化的时候改一下初始状态.可能存在无解或多解的情况,多解要 ...