简体   繁体   English

如何从数组中获取完整的单词而不是python中的第一个字母

[英]How to get full word from array instead of first letter in python

So I have this code:所以我有这个代码:

search_init = 'the string'
search = search_init.replace(' ', '+')
search_array = search.strip("+")
print search_array[1]

I expect to get "string" in the console's print.我希望在控制台的打印中得到“字符串”。 But instead I get "h".但相反,我得到了“h”。 How can I solve this?我该如何解决这个问题? I am trying to split "the string" into an array and then pull individual words from the array.我试图将“字符串”拆分为一个数组,然后从数组中提取单个单词。 (sorry for the newbie question lol) (抱歉新手问题哈哈)

You do a split based on space and then extract from index 1.您根据空间进行split ,然后从索引 1 中提取。

search_init = 'the string'
search = search_init.split(" ")
print search[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM