如何在 Python 中将字符串拆分为字符数组? [英] How to split a string into an array of characters in Python?

查看:58
本文介绍了如何在 Python 中将字符串拆分为字符数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在网上寻找将字符串拆分为字符数组的答案,但似乎找不到简单的方法

I've tried to look around the web for answers to splitting a string into an array of characters but I can't seem to find a simple method

str.split(//) 似乎不像 Ruby 那样工作.有没有不循环的简单方法?

str.split(//) does not seem to work like Ruby does. Is there a simple way of doing this without looping?

推荐答案

>>> s = "foobar"
>>> list(s)
['f', 'o', 'o', 'b', 'a', 'r']

您需要列表

这篇关于如何在 Python 中将字符串拆分为字符数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆