What types of "%" are?



Traceback (most recent call last):
File "python", line 8, in
TypeError: float argument required, not type

Im wondering what will be the %* to use, for the print sentence to compile??


            '1: int,2: float,3: string'


print '1: %f,2: %f,3: %f' % type(valInt),type(valFloat),type(valString)


In this exercise you don't have to use format specifiers (%s,%d or %f).

You have to just print the type of different data types.

Have Python print out the type of an int, a float, and a str string in the editor. You can pick any values on which to call type(), so long as they produce one of each.

when you do these...

"%f" % 2.3 ---> '2.300000'

"%d" % 2 -- > '2'

%s" % "s" --->'s'

"%f" % 2 --> '2.000000'
"%d" % 2.33 --> '2'

Note: they all are strings.

Now you can see you need to pass same data type as specifiers.

type(3) will return <class 'int'> which is not a data type.

Tho you can insert them as string and by using %s.
But it will not let you pass the exercise.

I'd suggest to print them separately.


print type(3)

and so on for float and string values.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.