如何删除任何给定输入中的所有空格?

时间:2015-09-27 18:39:05

标签: python

如何删除任何给定输入中的所有空格?例如:

askuser = input("Enter A Sentence:")  # --> fdshjh jfdhsj nhhsfd sdh hsfdjh shdks

2 个答案:

答案 0 :(得分:1)

这不是优雅的,但你可以去掉行尾,然后替换空格和标签:

xquery version "1.0-ml";
module namespace simple-xsl = "http://marklogic.com/rest-api/transform/simple-xsl";
import module namespace extut = "http://marklogic.com/rest-api/lib/extensions-util"
    at "/MarkLogic/rest-api/lib/extensions-util.xqy";
declare namespace xsl = "http://www.w3.org/1999/XSL/Transform";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare option xdmp:mapping "false";
declare private variable $transform-uri := "/marklogic.rest.transform/fda-transform-xsl/assets/transform.xsl";
declare function fda-transform-xsl:transform(
    $context as map:map,
    $params  as map:map,
    $content as document-node()  
) as document-node()?
{
    extut:execute-transform($transform-uri,$context,$params,$content)
};

答案 1 :(得分:0)

尝试使用以下列方式表示所有空格的正则表达式字符集:

new_input = re.sub(r'\s+', '', input('Enter A Sentence: ')) # whitespace is now empty str