0

Sorry if this is a noob question. But I am new to programming so I am still learning.

I have a string

string = "Hello Bye Hi" 

I split it up:

new_list_string = string.split 

output:

["Hello", "Bye", "Hi"] 

My question is how can I use this newly generated list, for example.

if I do this:

 new_list_string[1] 

I don't get "Bye", instead I get an error:

builtins.TypeError: 'builtin_function_or_method' object is not iterable 
1
  • 1
    string.split() you need to add parens to call the method, also try to avoid using string as a variable name. Commented Sep 25, 2014 at 0:15

4 Answers 4

2

the problem is you did string.split, and not string.split()

Deeper explanation: when you do string.split, you never actually call split. Therefore, it returns the function rather than the list. You need to call it with the syntax string.split()

Sign up to request clarification or add additional context in comments.

1 Comment

ohh.. wait let me try that. I'll let u know what I get.
0

try new_list_string = string.split()
then you should be able to access

new_list_string[0] new_list_string[1] new_list_string[2] 

Comments

0

try this...

new_list_string()[1] 

although it is better not to use string as a variable, because it is the name of a python module. Anyway, you should use...

s.split() 

Comments

0

To answer the question, you can use index(v) to find a value's index :).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.