Help me understand...

Asun Friere afriere at yahoo.co.uk
Thu May 8 01:04:51 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.
> 

The square brackets here do not indicate a list.  In describing a
command and its arguments square brackets traditionally denote
optional arguments as in :

foo arg0 [opt_arg1 [opt_arg2]]

which says foo takes the argument arg0, followed optionally by
opt_arg1, followed optionally by opt_arg2 (but only if opt_arg1 was
given.)  When you find a comma in the square bracket, as in your
example, this means that if you give the optional second argument, you
must separate it from the first using a comma.

> After 30 tries I got this to work
> s.split("n",3) - how come the quotes weren't in the help?

Because the quotes aren't necessary to the command, but only to
indicate a literal.  ie you could have written:
foo = "n"
s.split(foo, 3)




More information about the Python-list mailing list