[Tutor] Noob to Python - Need help with Variables

Ole Jensen learning.python@dbmail.dk
Thu Jun 5 11:34:01 2003


This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C32B88.5DE2D800
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

-----[snip]--------

=20
> ...and don't worry, you can always ask questions here if you get stuck =
at=20
> someplace ...but you really should get the basic stuff under your belt =
before=20
> you move on.
>=20
> (*) Introductory docs can be found at:
> http://www.python.org/doc/Intros.html
>     Look under "Introductions to Python programming for =
non-programmers"

>From one nooB to the other I agree totally with Steve that you should go =
through some of the tutorials.

Now the reason I am replying before you barely pressed the link is =
mostly because that I had a really difficult time finding this answer, =
as I have only seen this in one tutorial.
for now:
what you need to do is use the percent sign. Which as far as I now is =
called the mudulo operator, and in all but one of the tutorials I've =
been through this is only descriped as a way to calculate the remainder =
of a division. E.g.  7 / 4 =3D 1 with a remainder of 3, so in python 7 % =
4 =3D 3
But thats far from what the persent sign can do...
if you want to include a varible in a string e.g.:

>>> name =3D "Tony"
>>> str =3D "Hello, %s" % name
>>> print str
Hello, Tony

There's annother way to do it as well, but i'm not to sure about that:
keeping the varibles as is

>>> str =3D "Hello, =B4name=B4"
should print: Hello, Tony

however I get a unicode error so I'm obvously doing something wrong, if =
anybody else know about this method I would really like what im doing =
wrong!

Finally again as steve said you really need to go through some =
tutorials, these two I found extremly useful:

Alan Guald's http://www.freenetpages.co.uk/hp/alan.gauld/
and
Michael Williams' http://users.ox.ac.uk/~sann1276/python/handbook/

ohh and forgot about this one http://www.ibiblio.org/obp/thinkCSpy/ , =
"How to Think Like a Computer Scientist"

Now I might be a slow learner but I have never even heard of this =
'shutil.rmtree("d:\\tempint\"user"' (by the way I think need an end =
brace on that), but depending on how brave you are I would recommend =
getting down with the basics before you play around with something you =
could accidentally mess up.


Ole

------=_NextPart_000_001B_01C32B88.5DE2D800
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2726.2500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV>-----[snip]--------</DIV>
<DIV><BR>&nbsp;<BR>&gt; ...and don't worry, you can always ask questions =
here if=20
you get stuck at <BR>&gt; someplace ...but you really should get the =
basic stuff=20
under your belt before <BR>&gt; you move on.<BR>&gt; <BR>&gt; (*) =
Introductory=20
docs can be found at:<BR>&gt; <A=20
href=3D"http://www.python.org/doc/Intros.html">http://www.python.org/doc/=
Intros.html</A><BR>&gt;=20
&nbsp;&nbsp;&nbsp; Look under "Introductions to Python programming for=20
non-programmers"<BR></DIV>
<DIV>From one nooB to the other I agree totally with Steve that you =
should go=20
through some of the tutorials.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Now the reason I am replying before you barely pressed the link is =
mostly=20
because that I had a really difficult time finding this answer, as I =
have only=20
seen this in one tutorial.</DIV>
<DIV>for now:</DIV>
<DIV>what you need to do is use the percent sign. Which as far as I now =
is=20
called the mudulo operator, and in all but one of the tutorials I've =
been=20
through this is only descriped as&nbsp;a way to calculate the remainder =
of a=20
division. E.g. &nbsp;7 / 4 =3D 1&nbsp;with a remainder of 3, so&nbsp;in=20
python&nbsp;7 % 4 =3D 3</DIV>
<DIV>But thats far from what the persent sign can do...</DIV>
<DIV>if you want to include a varible in a string e.g.:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; name =3D "Tony"</DIV>
<DIV>&gt;&gt;&gt; str =3D "Hello, %s" % name</DIV>
<DIV>&gt;&gt;&gt; print str</DIV>
<DIV>Hello, Tony</DIV>
<DIV>&nbsp;</DIV>
<DIV>There's annother way to do it as well, but i'm not to sure about=20
that:</DIV>
<DIV>keeping the varibles as is</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; str =3D "Hello, =B4name=B4"</DIV>
<DIV>should print: Hello, Tony</DIV>
<DIV>&nbsp;</DIV>
<DIV>however I get a unicode error so I'm obvously doing something =
wrong, if=20
anybody else know about this method I would really like what im doing=20
wrong!</DIV>
<DIV>&nbsp;</DIV>
<DIV>Finally again as steve said you really need to go through some =
tutorials,=20
these two I found extremly useful:</DIV>
<DIV>&nbsp;</DIV>
<DIV>Alan Guald's <A=20
href=3D"http://www.freenetpages.co.uk/hp/alan.gauld/">http://www.freenetp=
ages.co.uk/hp/alan.gauld/</A></DIV>
<DIV>and</DIV>
<DIV>Michael Williams' <A=20
href=3D"http://users.ox.ac.uk/~sann1276/python/handbook/">http://users.ox=
.ac.uk/~sann1276/python/handbook/</A></DIV>
<DIV>&nbsp;</DIV>
<DIV>ohh and forgot about this one <A=20
href=3D"http://www.ibiblio.org/obp/thinkCSpy/">http://www.ibiblio.org/obp=
/thinkCSpy/</A>&nbsp;,=20
"How to Think Like a Computer Scientist"</DIV>
<DIV>&nbsp;</DIV>
<DIV>Now I might be a slow learner but I have never even heard of this=20
'shutil.rmtree("d:\\tempint\"user"' (by the way I think need an end =
brace on=20
that), but depending on how brave you are I would recommend getting down =
with=20
the basics before you play around with something you could accidentally =
mess=20
up.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Ole</DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_001B_01C32B88.5DE2D800--