【问题标题】:How can I remove whitespaces (multiple space, tab, nextline) from the input code in Python programming? [duplicate]如何从 Python 编程中的输入代码中删除空格(多个空格、制表符、下一行)? [复制]
【发布时间】:2021-01-31 05:54:52
【问题描述】:

如何在 Python 编程中从输入代码中删除空格(多个空格、制表符、下一行)? 例如,

input = "p y t h o n e x e r c i s e s"

input = "python exercises"

input = "python exercises\n"

我只想显示一个单词。这意味着输出将是“pythonexerecises” 如何使用 python 解决这个问题?

【问题讨论】:

标签: python newline spaces


【解决方案1】:
inp = "p y t h o n e x e r c i s e s"
out = ''.join(inp.split())
print(out)

【讨论】:

    猜你喜欢
    • 2018-05-03
    • 2011-07-29
    • 2016-07-02
    • 2012-11-19
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    相关资源
    最近更新 更多