細細.魚 发表于 2017-5-7 09:51:01

Python菜谱-逐一处理字符串中的字符

1.把字符串转为list

  


str="fengxuelianyi"
strList=list(str)
2.不需要创建list,可以直接使用for循环
  


for c in thestring:
do_something_with(c)
3.也可以使用for子句
  


results =
4.也可以使用map函数
  


results = map(do_something, thestring)
 
页: [1]
查看完整版本: Python菜谱-逐一处理字符串中的字符