Ejemplo 1: cómo dividir una entrada en python por coma
lst = input().split(',')#can use any seperator value inside '' of split
print (lst)
#given input = hello,world
#output: ['hello', 'world']
#another example
lst = input().split(' ; ')#can use any seperator value inside '' of split
print (lst)
#given input = hello ; world ; hi there
#output: ['hello', 'world', 'hi there']
Ejemplo 2: dividir una cadena por coma python
# We can use the split() function and put a "," in the parameter
# It'll return a list with the string split up by commas.
txt = "hello, my name is Peter, I am 26 years old"
x = txt.split(",")
print(x)
# You can also do this
for thing in x:
print(thing)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)