I have a string like this: Test:11747:v:0:27500:4760:4720:407
how can I put each of these sections of string (which split by ":") into a new string?
something like this: a = Test, b = 11747, etc.
Asked
Active
Viewed 133 times
1
mohamad danesh
- 326
- 1
- 6
- 21
-
You mean you want to *split* the string? – thefourtheye Sep 13 '15 at 06:42
-
`"Test:11747:v:0:27500:4760:4720:407".split(":")` returns a list that contains the required strings. If you want to assign them to variables you can do: `a, b, c, d, e, f, g, h = "Test:11747:v:0:27500:4760:4720:407".split(":")` – Nir Alfasi Sep 13 '15 at 06:42
2 Answers
1
You can use this:
"Test:11747:v:0:27500:4760:4720:407".split(":")
You will get a list of the splited string.
Ahsanul Haque
- 10,676
- 4
- 41
- 57
0
a = "Test:11747:v:0:27500:4760:4720:407"
b = a.split(':')
Here you have b as a list: ['Test', '11747', 'v', '0', '27500', '4760', '4720', '407']
Then you can loop it and make what ever you want.
for c in b:
print(c)
Ahsanul Haque
- 10,676
- 4
- 41
- 57
Mark Shuster
- 31
- 6