[Tutor] not a good tutorial, in my view

Remco Gerlich scarblac@pino.selwerd.nl
Sun, 18 Feb 2001 15:30:18 +0100

On Sun, Feb 18, 2001 at 09:54:50PM +0800, bxuef@freemail.sx.cn wrote:
> It appears the Python 2.0 tutorial are not written for beginners without
> programming background.

I agree. Try Alan Gauld's webpage instead, at
http://www.crosswinds.net/~agauld (there are a few others, on www.python.org
go to Documentation, then look for "Introductions", and "Introductions for

> 1. I typed:

If you write down a string, the \ is used to "escape" things. For instance,
if a string is enclosed between " ", you need a way to have a " inside the
string - you write it \".

Similarly, there are some special characters that you can't simply write down.
A newline is spelled as \n, a tab is spelled \t. \011 is the same thing as \t,
in another representation.

> >>>"doesn\t"
> # and it produced the following result:
> >>>'doesn\011'

See above. The \t you typed shows as \011 in the interpreter's representation.
The string is "doesn" followed by a tab character.

> >>> 'yes\'he said'
> "yes'he said"
> >>>>>> "\"yes,\" he said"
> '"yes," he said'
> what is the use of this slash? 

If you don't use the slash, Python thinks the ' means the end of the string.
Same for " in the second example.

> 2. What is the use of 'strip' here?
> >>> string.strip('str') + 'ing'
> 'string'

string.strip removes whitespace from the begin and end of a string.

Try this alternative:
>>> string.strip("       str     \n")+'ing'

(the \n is a newline, it also counts as whitespace)

> and why this does not work:
> >>> string.strip('str') 'ing'
> SyntaxError: invalid syntax
> It is explained in the tutorial, but I can not understand.

You have first a call to a function (string.strip) and then a string
('ing'). Python doesn't know what to do with that, this is not what Python
looks like. If you want to add them together, you can do so with +.

> 3. In the tutorial 3.1.3. Why there is the unicode part. 
> what's the use of unicode in programming?

Standard ASCII has only 127 different characters. That is not enough to
represent text in all the world's languages, by far. Unicode is newer, and
it has over 60,000 different codes. But moving programs like Python to
Unicode is a slow and complicated process, and I propose you ignore it
totally for now.

> I input this but why it did not produce the desired result?
> >>> u'Hello\\u0020World !'
> u'Hello\\u0020World !'

One backslash too many. \\ inside a string means simply \.

> The desired result should be
> >>>u'Hello World !'
> Under what conditions will the Interpreter shows the second prompt(...)?
> In the turtorial, it reads "for continuation lines it prompts with the 
> second prompt...".

If the command you started to enter isn't done yet. For instance, when you
still have a ( open without an ), or when you're writing a block of code, 
for instance after an if: statement:

>>> if 2 > 1:
...    print "whee"

It writes ... because you can still enter lines that belong to the 'if'

> I am a little frustrated by the tutorial, can anyone show me some links to
> the easier tutorial (for instance, Alan's)? Or hopefuly there will be a
> beginner's version of the tutorial.

See above.

Remco Gerlich