#python版一行内容分行输出
a="aA1一bB2二cC3三dD4四eE5五fF6六gG7七hH8八iI9九"
"""
分行输出为:
abcdefghi
ABCDEFGHI
123456789
一二三四五六七八九
"""
print("方法一:===============")
for r in range(0,4):
t=''
for s in range(0+r,len(a),4):
t=t+a[s]
print(t)
print("方法二:===============")
#=_=这个方法会不会看起来比较傻?
l=list(a)
ta=tb=tc=td=''
for r in range(0,9):
for s in range(0,4):
if s==0:
ta=ta+l.pop(0)
if s==1:
tb=tb+l.pop(0)
if s==2:
tc=tc+l.pop(0)
if s==3:
td=td+l.pop(0)
print(ta)
print(tb)
print(tc)
print(td)
print("方法3:回字有N种写法===============")
import string
ta=tb=tc=td=''
la=string.ascii_lowercase
ua=string.ascii_uppercase
nb=string.digits
ub="一二三四五六七八九"
for s in a:
if s in la:
ta=ta+s
if s in ua:
tb=tb+s
if s in nb:
tc=tc+s
if s in ub:
td=td+s
print(ta)
print(tb)
print(tc)
print(td)
print("方法4:回字有一种叫做正则的写法===============")
import re
#这正则写法感觉不科学,暂时没有好的想法
reg=["[a-z]","[A-Z]","\d","[^\da-zA-Z]"]
for s in reg:
rega=re.compile(s)
s=re.findall(rega,a)
print("".join(s))
"""
输出:
方法一:===============
abcdefghi
ABCDEFGHI
123456789
一二三四五六七八九
方法二:===============
abcdefghi
ABCDEFGHI
123456789
一二三四五六七八九
方法3:回字有N种写法===============
abcdefghi
ABCDEFGHI
123456789
一二三四五六七八九
方法4:回字有一种叫做正则的写法===============
abcdefghi
ABCDEFGHI
123456789
一二三四五六七八九
"""再给大家一个读取文件内容并分行输出的方法
f=open("shuju.txt","r")
content=f.read()
print content
for i in content:
print i
f.close()
f=open('shuju.txt','w')
f.write(content)
f.close()好了,小伙伴们自己好好研究下吧,很有意思。
”扩展PHP“说起来容易做起来难。PHP已经进化成一个日趋成熟的源码包几十兆大小的工具。要骇客如此复杂的一个系统,不得不学习和思考。构建本章内容时,我们最终选择了“在实战中学习”的方式。这不是最科学也不是最专业的方式,但是此方式最有趣,也得出了最好的最终结果。下面的部分,你将先快速的学习到,如何获得最基本的扩展,且这些扩展立即就可运行。然后你将学习到 Zend 的高级 API 功能,这种方式将不得
398
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号