Posts: 7
Threads: 3
Joined: Mar 2019
Mar-16-2019, 03:07 AM
(This post was last modified: Mar-16-2019, 03:14 AM by ichabod801.)
i am new to python and i am trying to get a better understanding on how to manipulate strings. Here is my program;
g='Hello world! What is your name?
print(g)
g.split(' ')
print(g.split()) How to do i manipulate the strings to get this output
Output: >>> ['Hello','world','!'],['what','is','your','name','?']
Any help on this issue is greatly appreciated.
Posts: 12,031
Threads: 485
Joined: Sep 2016
need closing quote on line 1
first split on '!'
which will give you a list with two cells
split each cell on space g1 = g[0].split() same for g[1]
append '!' to g[0]
print(g0, g1)
Posts: 9
Threads: 2
Joined: Jul 2018
Mar-17-2019, 08:52 AM
(This post was last modified: Mar-17-2019, 01:54 PM by Yoriz.)
g="Hello world ! what is your name ?"
g1=g.split(' ')
print(g1[0:3],end="")
print(',',end="")
print(g1[3:])
Posts: 7
Threads: 3
Joined: Mar 2019
Mar-18-2019, 11:44 PM
(This post was last modified: Mar-19-2019, 12:18 AM by lekuru01.)
(Mar-16-2019, 07:58 AM)Larz60+ Wrote: need closing quote on line 1
first split on '!'
which will give you a list with two cells
split each cell on space g1 = g[0].split() same for g[1]
append '!' to g[0]
print(g0, g1) Thank you for your response. One other question , how do you manipulate the spring to add addition strings to the original string. Thanks
(Mar-17-2019, 08:52 AM)saravanatn Wrote: g="Hello world ! what is your name ?"
g1=g.split(' ')
print(g1[0:3],end="")
print(',',end="")
print(g1[3:]) Thank you for your response, one additional question, what is I want to add more to the string, like this
g="Hello world ! what is you name ? my name is Daniel .
Posts: 12,031
Threads: 485
Joined: Sep 2016
several ways to do this, a few below
g = g + 'more text'
if python 3.6 or newer:
g = f'{g} more text'
Posts: 7
Threads: 3
Joined: Mar 2019
(Mar-19-2019, 02:19 AM)Larz60+ Wrote: several ways to do this, a few below
g = g + 'more text'
if python 3.6 or newer:
g = f'{g} more text'
Again, thank you for your response, but I am not sure If I understand you response. I am just trying to understand how to make multiple strings work. Thank you
g="Hello world ! what is your name ? my name is Daniel . I am fine "
g1=g.split(' ')
print(g1[0:3],end="")
print(',',end="")
[python] print(g1[3:}
Posts: 7
Threads: 3
Joined: Mar 2019
Mar-19-2019, 10:42 AM
(This post was last modified: Mar-19-2019, 10:55 AM by lekuru01.)
(Mar-19-2019, 06:41 AM)lekuru01 Wrote: (Mar-19-2019, 02:19 AM)Larz60+ Wrote: several ways to do this, a few below
g = g + 'more text'
if python 3.6 or newer:
g = f'{g} more text'
Again, thank you for your response, but I am not sure If I understand you response. I am just trying to understand how to make multiple strings work. Thank you
g="Hello world ! what is your name ? my name is Daniel . I am fine " g1=g.split(' ') print(g1[0:3],end="") print(',',end="") print(g1[3:} Reposting to adhere to the rule of the house
(Mar-18-2019, 11:44 PM)lekuru01 Wrote: (Mar-16-2019, 07:58 AM)Larz60+ Wrote: need closing quote on line 1
first split on '!'
which will give you a list with two cells
split each cell on space g1 = g[0].split() same for g[1]
append '!' to g[0]
print(g0, g1) Thank you for your response. One other question , how do you manipulate the spring to add addition strings to the original string. Thanks
(Mar-17-2019, 08:52 AM)saravanatn Wrote: g="Hello world ! what is your name ?"
g1=g.split(' ')
print(g1[0:3],end="")
print(',',end="")
print(g1[3:])
Thank you for your response, one additional question, what is I want to add more to the string, like this
g="Hello world ! what is you name ? my name is Daniel . I am fine
Thank you for your response, one additional question, what is I want to add more to the string, like this
g="Hello world ! what is you name ? my name is Daniel . I am fine g="Hello world ! what is your name ?"
g1=g.split(' ')
print(g1[0:3],end="")
print(',',end="")
print(g1[3:])
|