Re: [Tutor] Getting the type of a variable

2006-10-27 Thread Alan Gauld
"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

Re: [Tutor] Getting the type of a variable

2006-10-27 Thread wesley chun
> > 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

Re: [Tutor] Getting the type of a variable

2006-10-27 Thread Joshua Simpson
  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

Re: [Tutor] Getting the type of a variable

2006-10-27 Thread Etrade Griffiths
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:

Re: [Tutor] Getting the type of a variable

2006-10-27 Thread Asrarahmed Kadri
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

Re: [Tutor] Getting the type of a variable

2006-10-27 Thread Kent Johnson
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

Re: [Tutor] Getting the type of a variable

2006-10-27 Thread Glenn T Norton
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 "

[Tutor] Getting the type of a variable

2006-10-27 Thread Etrade Griffiths
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)