0
Can i use %s in print whatever the type of my variable is?
I use %s in print() whatever the variable type is and i don't have a problem. But is it really right? Is there a memory problem with it? Is there any case i can't/shouldn't use %s in python 3? thank you
3 Respostas
+ 1
You use %s when the variable is a string. If it is %f, you use a float, %i or %d for an int, etc.
Here is a reference
https://www.learnpython.org/en/String_Formatting
0
so you say that even though %s works even with integer and float type variables, i shouldn't use it like that?
0
When the object is not a string, it uses its string representation, which is returned by repr(). If you want to use the integer representation, you would use %d. For a float representation, %f.