How to print a string list as a single string without intermediate characters
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | def main(): key = [] mess=input('Write Text: ') for ch in mess: x = ord(ch) x = x-3 x = chr(x) key.append(x) print("Your code message is:",key) outFile = open("Encryptedmessage.txt","w") print(key, file=outFile) main() |
到目前为止,我已经写了这个A,它可以很好地工作,但我的问题是输出是
1 2 | Write Text: the Your code message is: ['q', 'e', 'b'] |
我想知道你怎么才能摆脱打孔机,这样输出就可以
1 2 | Write Text: the Your code message is: qeb |
1 | print("Your code message is:","".join(key)) |
str.join(iterable) Return a string which is the concatenation of the strings in the
iterable iterable. The separator between elements is the string
providing this method.
来源:https://docs.python.org/2.7/library/stdtypes.html?连接连接
您不希望在列表元素之间有任何分隔符,因此请使用空字符串
可能取代
1 | key=[] |
具有
1 | key="" |
替代
1 | key.append(x) |
具有
1 | key=key+x |
?