0

I am new to Python and i have a problem of converting the strings of words into a list of word and my string will be downward like this.

  • Hello 1

  • Hello 2

  • Hello 3

I want to convert to a list example: List=['Hello 1','Hello 2','Hello 3'] List[0]='Hello 1' ... How to do this? any help will appreciate.

Schrodinger
  • 39
  • 1
  • 9

2 Answers2

3

use split function:

hello_str = "hello1 hello2 hello3"
hello_list = hello_str.split()

this will result

['hello1', 'hello2', 'hello3']
Gokhan Gerdan
  • 1,222
  • 6
  • 19
0

Try this code:

st="Hello 1 \n Hello 2 \n Hello 3"
ArrStr=st.split("\n")
print(ArrStr)
Milan Tejani
  • 372
  • 5
  • 21