统计文本文件中最长行的长度和该行的内容
文本文件名为sample.txt,内容为:
123
asdfg
zxcvbnm
uiop1
str_count=0
str_code=''
for i in open("sample.txt",'r').readlines():
if len(i) > str_count:
str_count=len(i)
str_code=i
print("长度:%s,内容:%s"%(str_count,str_code))
如有帮助请采纳