Python判断字符串与大小写转换
“藤井白鸟”通过精心收集,向本站投稿了6篇Python判断字符串与大小写转换,下面就是小编整理后的Python判断字符串与大小写转换,希望大家喜欢。
篇1:Python判断字符串与大小写转换
这篇文章主要介绍了Python判断字符串与大小写转换的方法,有需要的小伙伴可以参考下,
判断字符串
s.isalnum #所有字符都是数字或者字母s.isalpha() #所有字符都是字母s.isdigit() #所有字符都是数字s.islower() #所有字符都是小写s.isupper() #所有字符都是大写s.istitle() #所有单词都是首字母大写,像标题s.isspace() #所有字符都是空白字符、\t、\n
大小写转换
s.upper() #把所有字符中的小写字母转换成大写字母s.lower() #把所有字符中的大写字母转换成小写字母s.capitalize() #把第一个字母转化为大写字母,其余小写s.title() #把每个单词的第一个字母转化为大写,其余小写
以上所述就是本文的全部内容了,希望大家能够喜欢,
篇2:Python写的英文字符大小写转换代码示例
这篇文章主要介绍了Python写的英文字符大小写转换代码示例,本文例子相对简单,本文直接给出代码实例,需要的朋友可以参考下
几行代码的小工具,用于进行如下转换
TRANSACTIONS ON CLOUD COMPUTING
=》
Transactions On Cloud Computing
代码如下:
rig = ‘TRANSACTIONS ON CLOUD COMPUTING‘
splited = orig.split(‘ ‘)
handled = ‘‘
for word in splited:
word = word[0] + word[1:].lower()
handled += (‘ ‘ + word)
handled = handled[1:]
print handled
#handled is ‘Transactions On Cloud Computing‘
篇3:python正则表达式判断字符串是否是全部小写示例
最近更 新
分析python服务器拒绝服务攻击代码
Python不规范的日期字符串处理类
python正则匹配抓取豆瓣电影链接和评论代
用python实现的去除win下文本文件头部BOM
Python中的Function定义方法
重命名批处理python脚本
python使用urllib模块和pyquery实现阿里巴
python基础教程之类class定义使用方法
python使用cookie库操保存cookie详解
python实现排序算法
热 点 排 行
Python入门教程 超详细1小时学会
python 中文乱码问题深入分析
比较详细Python正则表达式操作指
Python字符串的encode与decode研
Python open读写文件实现脚本
Python enumerate遍历数组示例应
Python 深入理解yield
Python+Django在windows下的开发
python 文件和路径操作函数小结
python 字符串split的用法分享
篇4:Python字符串的encode与decode研究心得乱码问题解决方法
-02-02pydev使用wxpython找不到路径的解决方法
2013-11-11python正则表达式抓取成语网站
-02-02使用python分析git log日志示例
2014-07-07Python重新引入被覆盖的自带function
2013-12-12python数据库操作常用功能使用详解(创建表/插入数据/获取数据)
2013-02-02通过python下载FTP上的文件夹的实现代码
2014-01-01下载安装setuptool和pip linux安装pip
2013-11-11python冒泡排序算法的实现代码
2014-07-07Python中的魔法方法深入理解
2014-03-03python读取csv文件示例(python操作csv)
篇5:Python字符串的encode与decode研究心得乱码问题解决方法
最近更 新
python list转dict示例分享
python读取html中指定元素生成excle文件示
python使用mysqldb连接数据库操作方法示例
Python MD5文件生成码
Pyramid Mako模板引入helper对象的步骤方
centos系统升级python 2.7.3
python逐行读取文件内容的三种方法
python实现代码行数统计示例分享
Python help函数用法详解
python操作MongoDB基础知识
热 点 排 行
Python入门教程 超详细1小时学会
python 中文乱码问题深入分析
比较详细Python正则表达式操作指
Python字符串的encode与decode研
Python open读写文件实现脚本
Python enumerate遍历数组示例应
Python 深入理解yield
Python+Django在windows下的开发
python 字符串split的用法分享
python 文件和路径操作函数小结
篇6:.Net程序员之Python基础教程学习判断条件与循环[Fourth Day]
今天学习Python的判断条件与循环操作,
一. 布尔变量:
在学习判断条件之前必须的了解bool变量,在Python中bool变量与C语言比较类似,与.net差别比较大,其中下面集中情况需要记住。
False, '', 0, (), [],{},None 为空,而True,12,'hello',[1] 这些普遍都为真. 其实可以简单理解为,无即是false,有既是true
>>>bool(True)
True
>>>bool(0)
False
>>>bool(1)
True
>>>bool('')
False
>>>bool('123')
True
>>>bool([])
二. IF 的使用.
Note: if后面用:号隔开,相当于C#和C语言的{} 对于包含的代码段用间隔号隔开。比如第三行 print '未成年人' 是if(age<18)的子方法,那么就要在前面空出几个空格.
age = 18
if(age<18):
print '未成年人'
elif(age<50):
print '成年人'
else:
print '老年人'
输出:'成年人'
age = 20
if(age<50):
if(age>18):
print '成年人'
三. While的使用:
x = 1
while x<=100:
print x
x+=1
四. For 用法:
names = ['Frank','Loch','Vincent','Cain']
for name in names:
print name
五.断言的使用: 断言主要用于测试的时候。如果断言不通过将会报错.
>>>age = 10
>>>assert age<20
>>>assert age<9 # 第一个断言通过了。第二个断言没有通过,所以报错了。
Traceback (most recent call last):
File “
”, line 1, in
assert age<9
AssertionError
六. 综合运用,
1. 下面有一个列表取出列表中的数字:
myList = ['Frank','Bob',123,456,789]
for val in myList:
if(type(val) is int): #type获取一个值得类型.
print val
输出结果是:
123
456
789
2. 打印出杨辉三角形: 10层的杨辉三角形,先声明一个二维数组,由于不能像C语言或者C++使用for(int index;index<10;index++),我选择了使用while的双层循环
rowIndex = 1
columnIndex = 0
myList = [[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0]]
print myList
print(myList[9][9])
while rowIndex < 10:
while columnIndex <= rowIndex:
if(rowIndex==1):
myList[1][0]=1
myList[1][1]=1
else:
if(columnIndex==rowIndex):
myList[rowIndex][columnIndex]=1
else:
myList[rowIndex][columnIndex]=myList[rowIndex-1][columnIndex-1]+myList[rowIndex-1][columnIndex]
columnIndex+=1
columnIndex=0
rowIndex+=1
line = ''
for row in myList:
for val in row:
if(val!= 0):
line = line + str(val)+' '
print line
line=''
运行结果:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
复制代码
【Python判断字符串与大小写转换】相关文章:
3.字母大小写对照表
4.同义词转换
5.C字符串笔试题
10.asp实现截取字符串函数






文档为doc格式