Search code examples
pythonphpexplode

How can i use this statement in python?


I have this in php and i would like to know how to set up this but in python

<?php
  $to_parse = 'palabras,para,separar';
  $array = explode ( ',', $to_parse);
  foreach ( $array as $palabra ) {
  echo $palabra . '>br/<';
  }
?>

i had tried this:

to_parse = 'palabras,para,separar'
array = list(to_parse)
 
for palabra in palabra:
 print(palabra)

Solution

  • How about something like this:

    to_parse = 'palabras,para,separar'
    array = to_parse.split(',')
    for palabra in array:
      print("%s >br/<" % palabra)