What types of "%" are?


#1



https://www.codecademy.com/courses/python-beginner-c7VZg/3/5?curriculum_id=4f89dab3d788890003000096


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??

output:

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


valInt=5
valFloat=5.1
valString='hello'

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


#2

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'

also...
"%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.

like...

print type(3)

and so on for float and string values.


#3

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