[Tutor] #3 Text problem
alan.gauld at freenet.co.uk
Wed Jun 8 19:17:17 CEST 2005
> Subject: [Tutor] FW: Tutor Digest, Vol 16, Issue 21, #3 Text problem
Its best not to reply to the list digest header mail!
If for no other reason than the fact you send the whole
digest out with your mail which isn't very friendly
for those still using slow dial up!
> I tried your suggestion but it does not work for me. I get a syntax
> error at use of the first question mark when trying it in Idle.
> When I try it from the desktop, it just flashes a black screen and
> returns me to the desktop.
Try adding a line:
raw_input('Hit enter to quit')
at the end of your program. It sounds like its running and exiting
before you can reads it!
> What is the question mark used for? I looked up the use of % and the
> glossary says it returns the modulus.
Thats one use but its also used for interpolating text into strings as
s = 'A string with the number %d in it" % 42
s now contains 'A string with the number 42 in it'
So the % inserts the 42 at the position marked by %d (where d=decimal
You can insert other type values too. This is known as a format
try searching the help for that.
> I don't understand why I would want the modulus of anything.
Modulus (ie remainder part of an integer division) is very useful for
all sorts ofthings in programming, I'd be surprised if you never found
a use for it! :-)
More information about the Tutor