Help me understand...

drs drs at ecp.cc
Wed May 7 02:14:05 EDT 2003


"Norm" <norm at cheers.com> wrote in message
news:3eb883c1_7 at corp.newsgroups.com...
> I'm learning this slowly...
>
> As I read the syntax of using split it says this in IDLE.
> s.split(sep [,maxsplit]]) -> list of strings
>
> Now what I misunderstood out of this was that I should use [brackets] and
a
> ,comma such as this.
>
> s.split([n ,[3]]) - which of course didn't work.
>
> After 30 tries I got this to work
> s.split("n",3) - how come the quotes weren't in the help?


sep is short for separator.  You could use ",", or you could have a variable
equal to the separator, i.e.

>>> x = ","
>>> s.split(x)
or
>>> s.split(",")

further, the quotes indicate a string, and since a string can only be split
on a string, that is, there cannot be another data type embedded in a
string, they are implied.

generally (and this is true for almost any computer language you are likely
to encounter), the brackets around a function argument indicate that it is
optional.


-d






More information about the Python-list mailing list