代码如下:
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 3.py #coding=utf-8 ev =
""" 1evilxr 2www 3nihao 4evilxr.com 5dkfjls 6cnblog 7ldskf 8guess 9right """ print
ev #打印ev ev1 =
ev.replace( ‘\n‘ ,‘‘).strip() #去掉ev首尾的空格 print
ev1 a =
ev1.find( " " ) #寻找第一个空格的位置 w1 =
ev1[:a] #利用切片切出第一个部分 print
w1 b =
a while
b < =
len (ev1) and
b ! =
- 1
: #如果不限制b不为-1的话,就会是死循环 while
ev1[a] = =
" " : a =
a +
1 b =
ev1.find( " " ,a) if
b = =
- 1 : print
ev1[a:] else : print
ev1[a:b] a =
b |
运行结果:
1
2
3
4
5
6
7
8
9
10
11
12
13 |
[root@localhost test] # python 3.py 1evilxr
2www 3nihao
4evilxr .com 5dkfjls
6cnblog 7ldskf
8guess 9right 1evilxr
2www 3nihao
4evilxr .com 5dkfjls
6cnblog 7ldskf
8guess 9right 1evilxr 2www 3nihao 4evilxr .com 5dkfjls 6cnblog 7ldskf 8guess 9right |
原文地址:http://www.cnblogs.com/evilxr/p/3770121.html