pyton 字符串除去空格和替换删除

一、去除空格

  strip()

1
2
3
4
"  xyz  ".strip()      # returns "xyz"
"  xyz  ".lstrip()      # returns "xyz  "
"  xyz  ".rstrip()      # returns "  xyz"
" x y z ".replace(' ', '')  # returns "xyz"
 

二、替换 replace("space","")

  用replace("\n", ""),后边的串替换掉前边的

 

 

 

 

把str字符串转成字典(eval

str = '{"token":"NjQtV3Q4RnpPQ0U=","license":"937ce8e8cbe97f0d58ea769aa045c75b"}'
print(str)
dic = eval(str)
print(dic)
print(type(dic))

 

 

posted @ 2020-12-02 15:10  没有尾巴的狗  阅读(101)  评论(0编辑  收藏  举报