|
1
2
3
4
5
6
7
8
9
10
11
12 |
>>> ev1 =
‘evilxr‘>>> ev2 =
‘ev1il2xr3‘>>> ev3 =
‘.,/!@#‘>>> a =
ev1.isalnum()>>> print
aTrue>>> b =
ev2.isalnum()>>> print
b True>>> c =
ev3.isalnum()>>> print
cFalse |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
>>> ev1.isalpha()True>>> ev2.isalpha()False>>> ev2.isdigit()False>>> ev3.isdigit()False>>> ev2.isalpha()False>>> ev4.isdigit()True>>> ev4.isalpha()False>>> |
可以用来检测密码的强度~
|
1
2
3
4
5
6
7
8
9 |
>>> xr =
raw_input(‘Please input your password:‘)Please input
your password:evilxr1234>>> xr.isalpha()False>>> xr.isdigit()False>>> xr.isalnum()True>>> |
|
1
2
3
4
5
6
7 |
>>> xr =
raw_input(‘Please input your password:‘)Please input
your password:EVILXR>>> xr.islower() #xr的内容是小写的吗?False>>> xr.isupper() #xr的内容是大写的吗?True>>> |
|
1
2
3
4
5
6
7 |
>>> xr1 =
‘ ‘>>> xr1.isspace()True>>> xr2 =
‘ evilxr ‘>>> xr2.isspace()False>>> |
|
1
2
3
4
5
6
7
8
9 |
>>> ‘evilxr‘.upper() #将小写字符全转换为大写‘EVILXR‘>>> ‘HEY,WELCOME TO MY BLOG!‘.lower() #将大写字符全转换为小写‘hey,welcome to my blog!‘>>> ‘Hey,My name is Evilxr!‘.upper() #大小写混合的也能转‘HEY,MY NAME IS EVILXR!‘>>> ‘Hey,My name is Evilxr!‘.lower()‘hey,my name is evilxr!‘>>> |
|
1
2
3
4
5
6
7
8
9
10
11
12 |
[root@localhost test]# cat 1.pyev1 =
‘ ev il xr ‘print
ev1ev2 =
ev1.lstrip() #去掉左边print
ev2ev3 =
ev1.rstrip() #去掉右边print
ev3[root@localhost test]# python 1.py ev il xr ev il xr ev il xr |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 |
[root@localhost test]# cat 2.pys1 =
‘.com‘s2 =
‘.cn‘s3 =
‘www.‘s4 =
‘www.evilxr.com‘if
s4.startswith(s3): print
‘startswith www‘else: print
‘start is not www‘if
s4.endswith(s1): print
‘endswith is com‘elif
s2.endswith(s2): print
‘endswith is cn‘else: print
‘endswith is not com and cn‘[root@localhost test]# python 2.pystartswith wwwendswith is
com[root@localhost test]# |
|
1
2
3
4
5
6
7
8
9
10
11
12
13 |
>>> ev =
‘www.evilxr.com‘>>> id
(ev)3078278264L>>> s1 =
ev.replace(‘e‘,‘E‘)>>> print
s1www.Evilxr.com>>> id(s1)3078278584L>>> ev1 =
ev.replace(‘ev‘,‘EV‘)>>> print
ev1www.EVilxr.com>>> id(ev1)3078278504L |
|
1
2
3
4
5
6
7
8
9
10
11 |
>>> ev2 =
ev.replace(‘evilxr‘,‘evilxr.upper()‘)#upper()被当成了要被替换内容的一部分>>> print
ev2www.evilxr.upper().com>>> ev3 =
ev.replace(‘evilxr‘,‘evilxr‘.upper())#正确的应该是这个>>> print
ev3www.EVILXR.com>>> id(ev2)3078232832L>>> id(ev3)3078278704L>>> |
|
1
2
3
4
5
6
7
8
9
10
11 |
#用切片看下>>> ev =
‘evilxr‘>>> ev1 =
ev[:3]>>> print
ev1evi>>> ev2 =
ev[4:]>>> print
ev2xr>>> ev3 =
ev[:3]+‘L‘+ev[4:]>>> print
ev3eviLxr |
原文地址:http://www.cnblogs.com/evilxr/p/3769577.html