游戏ui设计网站鞍山网站
web/
2025/9/29 9:11:51/
文章来源:
游戏ui设计网站,鞍山网站,做微信小程序和做网站,做网站如何把栏目放到首页Given a string and we have to split into array of characters in Python. 给定一个字符串#xff0c;我们必须在Python中拆分为字符数组。 将字符串拆分为字符 (Splitting string to characters) 1) Split string using for loop 1)使用for循环分割字符串 Use for loop t…Given a string and we have to split into array of characters in Python. 给定一个字符串我们必须在Python中拆分为字符数组。 将字符串拆分为字符 (Splitting string to characters) 1) Split string using for loop 1)使用for循环分割字符串 Use for loop to convert each character into the list and returns the list/array of the characters. 使用for循环将每个字符转换为列表并返回字符的列表/数组。 Python program to split string into array of characters using for loop Python程序使用for循环将字符串拆分为字符数组 # Split string using for loop
# function to split string
def split_str(s):
return [ch for ch in s]
# main code
string Hello world!
print(string: , string)
print(split string...)
print(split_str(string))
Output 输出量 string: Hello world!
split string...
[H, e, l, l, o, , w, o, r, l, d, !]
2) Split string by converting string to the list (using typecast) 2)通过将字符串转换为列表来分割字符串(使用类型转换) We can typecast string to the list using list(string) – it will return a list/array of characters. 我们可以使用list(string)将字符串类型转换到列表中-它会返回一个字符列表/数组。 Python program to split string into array by typecasting string to list Python程序通过将字符串类型转换为列表将字符串拆分为数组 # Split string by typecasting
# from string to list
# function to split string
def split_str(s):
return list(s)
# main code
string Hello world!
print(string: , string)
print(split string...)
print(split_str(string))
string: Hello world!
split string...
[H, e, l, l, o, , w, o, r, l, d, !]
翻译自: https://www.includehelp.com/python/split-a-string-into-array-of-characters.aspx
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/83814.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!