2022年9月28日 星期三

Python print 文字時,文字與文字之間可以加一些符號

Python print 文字時,文字與文字之間可以加一些符號,感覺滿有趣的。

print(1, 2, 3, 4)
print(1, 2, 3, 4, sep='*')
print(1, 2, 3, 4, sep='#', end='&')
print('I love {0} and {1}'.format('bread','butter'))
print('I love {1} and {0}'.format('bread','butter'))
#直接寫到檔案裡,滿方便der
with open('out.txt', 'a+') as f:
    print('1,2,3', sep='%' , file=f)

沒有留言:

張貼留言