|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码:
str1 = '''拷贝过来的字符串'''
list1 = []
for each in str1:
if each not in list1:
if each == '\n':
print('\\n', str1.count(each))
else:
print(each, str1.count(each))
list1.append(each)
结果:
拷 1
贝 1
过 1
来 1
的 1
字 1
符 1
串 1
为什么不是:
拷 1 贝 1 过 1 来 1 的 1 字 1 符 1 串 1
>>> help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
- ## help(print)可以看到print方法的多个value直接的分隔符默认为空格(sep = ' '),结尾默认为换行(end='\n')。
- ## 想得到你需要的效果只要将end = ' '(空格)就可以了。
- print('\\n', str1.count(each), end = ' ')
- print(each, str1.count(each), end = ' ')
复制代码
|
|