Python String into array

Posted under » Python on 25 July 2022

Just like PHP explode, python too can make string into array

txt = "Hi, My name is LKY, and I love you"
x = txt.split(", ")
print(x)

Setting the maxsplit parameter to 1, will return a list with 2 elements!

x = txt.split(", ", 1)

If there is no delimiter, you can split each char including spaces by

list("Hi, My name is LKY, and I love you")

To see the array,

print (x[0])
print (x[1])
print (x[2])

You can use split to get integers in the string

status = 'LKY is no 1 PM'
pm_no = int(status.split(' ')[3])

Where the [#] is the number of spaces delimited.

For Concate string

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data