[Tutor] Declare empty string variable?

Volker Hoffmann Volker Hoffmann <volker@omega-fleet.dyndns.org>
Sun Dec 29 05:52:01 2002


Hi,

at first I just want to say hi. I've been reading on digests for a
couple of months (rather irregularily though) as I didn't have much
time for getting into python. Now I have some spare time and I'm gonna
be starting of with a possible stupid question :-).

I want to write a program that converts decimal numbers into binary
format. That should be a fairly easy task, but not with my limited
knowledge of python. Here's how my code looks so far:

> ### Decimal to Binary Conversion
> deci=input("Decimal? --> ")
> dual= <--- declaration
> ...
> while deci>0:
>     dual_tmp=deci%2
>     dual=dual_tmp, dual <--- change dual here
>     deci=deci/2
> print "Binary is", dual

Now I want the variable "dual" to be the output where the binary is
being stored. However, since I assume that all variables have to be
initialized in python I don't have any clue HOW to make dual a string
variable that's being updated every time in the while-loop.

Now, how do I have to declare "dual" to be a string and without any
value at the beginning? Is there any way like in pascal where it's
beging declared like this:

> var
>  dual:string;

Thanks in advance,
- Volker

-- 
"Earth is the cradle of mankind,
  but one cannot live in the cradle forever."
   - Konstantin Tsiolkovsky