1. 使用print 函数输出字符串时,如何用逗号 (,) 分隔
print('aa', 'bb')
print('aa', 'bb', sep=',')
aa bb
aa,bb
2. 使用print 函数输出字符串时,如何不换行
print('hello')
print('world')
print('hello', end=' ')
print('world')
hello
world
hello world
3. 如何用print 函数格式化输出
s = 'road'
x = len(s)
print('The length of %s is %d' % (s, x))
from io import StringIO
import sys
old_stdout = sys.stdout
result = StringIO()
sys.stdout = result
print('The length of %s is %d' % (s, x))
sys.stdout = old_stdout
result_str = result.getvalue()
print('result_str', result_str, sep=': ')
The length of road is 4
result_str: The length of road is 4
11 - 去掉列表或元组中的重复元素