马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
temp= 'ilovefishc.com'
temp1=list(temp)
temp1
['i', 'l', 'o', 'v', 'e', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm']
temp2=tuple(temp1)
temp2
('i', 'l', 'o', 'v', 'e', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm')
temp3=str(temp2)
temp3
"('i', 'l', 'o', 'v', 'e', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm')"
列表、元组、字符串之间相互转换以后,得到的字符串和原字符串相差甚远,
如何通过快速的方法去掉temp3字符串中的括号、单引号和逗号,使新生产的字
符串与原字符串相同。
- >>> temp= 'ilovefishc.com'
- >>> temp1=list(temp)
- >>> temp1
- ['i', 'l', 'o', 'v', 'e', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm']
- >>> str1 = ''.join(temp1)
- >>> str1
- 'ilovefishc.com'
- >>> temp2=tuple(temp1)
- >>> temp2
- ('i', 'l', 'o', 'v', 'e', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm')
- >>> str2 = ''.join(temp2)
- >>> str2
- 'ilovefishc.com'
- >>> temp3=str(temp2)
- >>> temp3
- "('i', 'l', 'o', 'v', 'e', 'f', 'i', 's', 'h', 'c', '.', 'c', 'o', 'm')"
- >>> str3 = ''.join(eval(temp3))
- >>> str3
- 'ilovefishc.com'
- >>>
复制代码
|