"Etrade Griffiths" <[EMAIL PROTECTED]> wrote
>
> I want to check the type of a variable so that I know which format
> to use
> for printing eg
That's sometimes necessary but you may find that just
using %s will suffice.
print "%s\n" % 42
print "%s\n" % "42"
print "%s\n" % 42.0
You usually only
> > I want to check the type of a variable so that I know which format to use
> > for printing eg
> >
> Alternatively, you could just cast it as a string.
what joshua is saying is that for just displaying something, that it's
just as easy to convert it to a string, or, if you're using print, to
no
On 10/27/06, Etrade Griffiths
<[EMAIL PROTECTED]>
wrote:
Hi
I want to check the type of a variable so that I know which format to
use
for printing egAlternatively, you could just cast it as a string.
___
Tutor maillist - Tutor@python.org
http
Thanks, guys - like so many things, easy when you know how!
Alun Griffiths
At 14:27 27/10/2006, you wrote:
Use this:
if type(a) == type(1):
print "a is int %d"
elif type(a) == type(1.1):
...
HTH..
Regards,
Asrarahmed Kadri
On 10/27/06, Etrade Griffiths
<[EMAIL PROTECTED]>
wrote:
Use this:
if type(a) == type(1):
print "a is int %d"
elif type(a) == type(1.1):
...
HTH..
Regards,
Asrarahmed Kadri
On 10/27/06, Etrade Griffiths <[EMAIL PROTECTED]> wrote:
HiI want to check the type of a variable so that I know which format to usefor printing eg
def print_correct_f
Etrade Griffiths wrote:
> Hi
>
> I want to check the type of a variable so that I know which format to use
> for printing eg
>
> def print_correct_format(a):
>
> if type(a) == 'int':
> print "a is an integer, value %i" % (a)
> elif type(a) == 'float':
> p
Etrade Griffiths wrote:
>Hi
>
>I want to check the type of a variable so that I know which format to use
>for printing eg
>
>def print_correct_format(a):
>
> if type(a) == 'int':
> print "a is an integer, value %i" % (a)
> elif type(a) == 'float':
> print "
Hi
I want to check the type of a variable so that I know which format to use
for printing eg
def print_correct_format(a):
if type(a) == 'int':
print "a is an integer, value %i" % (a)
elif type(a) == 'float':
print "a is a float, value %f" % (a)