python string method
嗯,学习其它语言没这样全练过,嘻嘻
//test.py
1 # -*- coding: UTF-8 -*-
2
3 str = "i am worker"
4 print str.capitalize()
5 print str.center(20)
6 print str.count(' ')
7 print str.count(' ', 0, 4)
8 str1 = "中国"
9 str1.decode('utf-8').encode('gb2312')
10 print str1
11 str2 = u'中国'
12 str2.encode('gb2312')
13 print str2
14 print str.endswith('er')
15 print str.endswith('er', 0, 6)
16 str3 = '1 3 5'
17 print str3
18 print str3.expandtabs()
19 print str3.expandtabs(1)
20 print str.find('m', 0, len(str))
21 #print str.index('h', 0, len(str)) #exception
22 print ''.isalnum()
23 print '?1a'.isalnum()
24 print '1a'.isalnum()
25 print '1'.isalpha()
26 #print 'isdecimal', '1a'.isdecimal() #no implement
27 print 'isdigit', '1a'.isdigit()
28 #print 'isnumeric', '1a'.isnumeric() #no implement
29 print 'islower', '1a'.islower()
30 print ' '.isspace()
31 print 'You are fool'.istitle()
32 print 'You Are Fool'.istitle()
33 print '1a'.isupper()
34 print 'and'.join(['1', '2', '3'])
35 print '123'.ljust(10) #make no sense of
36 print 'ABC'.lower()
37 print 'abc'.upper()
38 print ' abAB'.lstrip()
39 #print '123abc'.maketrans('123', 'ABC') #no implement
40 print '123'.partition('2')
41 print '123'.partition('1')
42 print '123'.partition('3')
43 print '123'.partition('4')
44 print '113'.replace('1', '2')
45 print '113'.replace('1', '2', 1)
46 print '11a'.rfind('a')
47 print '11a'.rindex('a')
48 print '123'.rjust(8)
49 print '123'.rpartition('2')
50 print '123 '.rstrip()
51 print '12134'.split('1')
52 print '12134'.split('1', 1)
53 print '1\r2\r\n3\n'.splitlines(True)
54 print '1\r2\r\n3\n'.splitlines(False)
55 print '123'.startswith('1')
56 print ' 123 '.strip()
57 print 'AbAbAb'.swapcase()
58 print 'abc def hgj'.title()
59 print '1aAbB?><'.translate(None, '<>')
60 print '123'.zfill(8)
61 print u'123'.isdecimal()
62 print u'AEBF'.isdecimal()
//result
# python test.py
I am worker
i am worker
2
1
中国
中国
True
False
1 3 5
1 3 5
1 3 5
3
False
False
True
False
isdigit False
islower True
True
False
True
False
1and2and3
123
abc
ABC
abAB
('1', '2', '3')
('', '1', '23')
('12', '3', '')
('123', '', '')
223
213
2
2
123
('1', '2', '3')
123
['', '2', '34']
['', '2134']
['1\r', '2\r\n', '3\n']
['1', '2', '3']
True
123
aBaBaB
Abc Def Hgj
1aAbB?
00000123
True
False
Finally:
肯定有你用得着的
python string method的更多相关文章
- Python string objects implementation
http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects impleme ...
- python string module
String模块中的常量 >>> import string >>> string.digits ' >>> string.letters 'ab ...
- python string
string比较连接 >>> s1="python string" >>> len(s) 13 >>> s2=" p ...
- The internals of Python string interning
JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A fe ...
- Python string replace 方法
Python string replace 方法 方法1: >>> a='...fuck...the....world............' >>> b=a ...
- Python string interning原理
原文链接:The internals of Python string interning 由于本人能力有限,如有翻译出错的,望指明. 这篇文章是讲Python string interning是如何 ...
- [Python] String Join
Let's introduce a new string method, join: >>> nautical_directions = "\n".join([& ...
- [Python] String Formatting
One particularly useful string method is format. The format method is used to construct strings by i ...
- [Python] String strip() Method
Description The method strip() returns a copy of the string in which all chars have been stripped fr ...
随机推荐
- js对象属性两种调用bug
jsobj.url_3[0]=url_3[1];这就错误jsobj.url_3[0]红色看成一个整体的0的属性,这就错了 TypeError: Cannot set property '0' of u ...
- parent对象
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...
- zabbix监控主机CPU使用率
zaibix默认模板针对CPU只有监控负载(load)没有监控CPU使用率 选择配置-模板-Template OS Windows-监控项 创建监控项 创建监控图形 查看图像结果
- vmware虚拟的ubuntu18.04死机,尝试关闭时关机报“虚拟机xxx繁忙”
找到虚拟机文件所在目录 打开vmware.log,第一行,找pid到pid=xxx,这就是CPU进程的id. 打开资源监视器,选CPU选项卡,找到这个PID,右键,结束进程. 再打开vmware尝试启 ...
- spark application提交应用的两种方式
bin/spark-submit --help ... ... --deploy-mode DEPLOY_MODE Whether to launch the driver program loc ...
- mysql帮助命令
HELP contents 查看MySQL命令的使用. eg: HELP 'Data Type' 查看所有的数据类型的使用方法.
- Xcode报错Expected selector for Objective-C and Expected method body
昨天把键盘拿起来拍一下清清灰,然后就发现Xcode报错了,Xcode报错Expected selector for Objective-C and Expected method body,也不知道什 ...
- sshd_config配置详解
sshd_config配置详解 名称 sshd_config - OpenSSH SSH 服务器守护进程配置文件 大纲 /etc/ssh/sshd_config 描述 sshd(8) 默认从 /etc ...
- MSSQL2008 部署及开启远程连接
最近不少用户在windows2003 server 32位操作系统上安装SQL Server2008总是失败,出现大量错误.今天经过通过我反复测试安装,找出了一个便捷的安装方法,节省大家宝贵时间,具体 ...
- Linux下Redis的安装与启动
一. 进入目录(我们准备将redis装入opt文件夹) $ cd /opt/ 二.下载redis压缩包 $ wget http://download.redis.io/releases/redis-4 ...