Discuss / Python / homework

homework

Topic source

gitKong

#1 Created at ... [Delete] [Delete and Lock User]
abc.txt

123

Hello

World

Gitkong

fpath = 'abc.txt'

with open(fpath, 'r') as f:
    l = []
    for line in f.readlines():
         # 把末尾的'\n'删掉
        c = line.strip()
        if c != '':
            l.append(c)
    print(''.join(l))
输出:123HelloWorldGitkong

  • 1

Reply