Home  >  Q&A  >  body text

python - 输入一个原始字符串,例如 hello world。 输出转换后的字符串,例如 hello%20world。

输入一个原始字符串, hello world。 输出转换后的字符串, hello%20world。

新手 不会呀 求大神教怎么才能这样输出。。。。。

迷茫迷茫2741 days ago1300

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 17:42:59

    If it is a dict of parameters:

    from urllib import urlencode
        data = {
             'name': 'hello world'
        }
        print urlencode(data)

    If it is a string:

    from urllib import quote
        quote('hello world')

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:42:59

    from urllib import quote
    quote(str)

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:42:59

    I use a = raw_input()
    a = a.replace(' ','%20')
    print a

    Solved. I couldn't come up with an answer because I misplaced print. . . Thank you all great gods

    reply
    0
  • Cancelreply