Help me understand...

Steven Taschuk staschuk at telusplanet.net
Wed May 7 12:12:47 EDT 2003


Quoth Norm:
> 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?
> 
> What is the darn rules for reading help/man/info/syntax in Python?

The brackets indicate optionalness.  This is a typical convention
in computer writing.  (See how man pages refer to optional
command-line switches, for example.)

The quotes are not part of the syntax for .split(), so it would be
inappropriate for the help to mention them.  They are part of
"string literal" syntax; they are for making a string.  But you
could also call .split() using a variable name:

    if foo():
        separator = ';'
    elif bar():
        separator = '/'
    else:
        separator = 'jfkdsjflksjfk'
    parts = s.split(separator, 3)

Note that there are no quotes in this call to .split().

-- 
Steven Taschuk              Aral: "Confusion to the enemy, boy."
staschuk at telusplanet.net    Mark: "Turn-about is fair play, sir."
                             -- _Mirror Dance_, Lois McMaster Bujold





More information about the Python-list mailing list