Noob question: Is all this typecasting normal?

TechieInsights GDoermann at gmail.com
Fri Jan 2 16:47:25 EST 2009


You can use the built-in string formatting options and operations.
2.5: http://www.python.org/doc/2.5.2/lib/typesseq-strings.html
2.6: http://docs.python.org/library/string.html

In essence, you can do:

print "You still have $%i remaining" %(money)

On Jan 2, 2:15 pm, sprad <jsp... at gmail.com> wrote:
> I've done a good bit of Perl, but I'm new to Python.
>
> I find myself doing a lot of typecasting (or whatever this thing I'm
> about to show you is called), and I'm wondering if it's normal, or if
> I'm missing an important idiom.
>
> For example:
>
> bet = raw_input("Enter your bet")
> if int(bet) == 0:
>     # respond to a zero bet
>
> Or later, I'll have an integer, and I end up doing something like
> this:
>
> print "You still have $" + str(money) + " remaining"
>
> All the time, I'm going int(this) and str(that). Am I supposed to?




More information about the Python-list mailing list