码迷,mamicode.com
首页 > 编程语言 > 详细

python字符串的使用(week2_day2)

时间:2016-08-24 12:58:41      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

本文主要介绍:字符串的一些常用的使用方法

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 # author by lh
 4 
 5 s = Hello Lh
 6 s2 = 12h
 7 
 8 print(s.strip())          # 去掉前后的空格
 9 print(s.lstrip())         # 去掉前面的空格
10 print(s.rstrip())         # 去掉后面的空格
11 print(s.lower())          # 将字符串中的所有大写字母转换成小写
12 print(s.upper())          # 将字符串中的所有小写字母转换成大写
13 print(s.islower())        # 判断字符串中所有字母是否是小写
14 print(s.isupper())        # 判断字符串中所有字母是否是大写
15 print(s.find(l))        # 查找指定字符串的索引位置
16 print(s2.join(s))         # h-e-l-l-o-l-h 通过s2连接s
17 print(s.split(o))       # 通过指定的字符分割字符串
18 print(s.startswith(e))  # 判断字符串是否以某个内容开头
19 print(s.endswith(h))    # 判断字符是否以某个字符结尾
20 print(s.isdigit())        # 判断字符串是否全是数字
21 print(s.isalnum())        # 判断字符串是否包含字母或数字
22 print(s.isalpha())        # 判断字符串中是否全是字母
23 print(s.title())          # 把字符串转化成标题(标题:每个单词的首字母大写)
24 print(s.istitle())        #判断字符串是否是标题

 

python字符串的使用(week2_day2)

标签:

原文地址:http://www.cnblogs.com/pythonlh/p/5802058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!