+ 1
How does print ("hey %s there" % "you") gives output as hey you there?
What's with that percentage sign?
5 Respuestas
+ 7
Someone else will probably be able to explain it more correctly, but %s is basically a place holder for a string. I know for C, C++ and Java's printf functions and method there are others like %d which is used for integer values and %f for floating point numbers. For example in Java System.out.print ("Hi " + 123) and System.out.printf ("%s %d", "Hi", 123) would both output Hi 123. Sorry for the poor explanation.
+ 5
I had no clue either for years even after 3 Java courses in college. One instructor finally started covering it while I was a teaching assistant.
+ 2
Shit.. I had Java in my academics and i never knew it.. Guess my academy book was shit too.
+ 1
Woh.. That would have been a shock
+ 1
Hi,
By seeing your syntax I believe you're using python.
When you type %s, within double codes means you are reserving space for a value to be entered.
So, what the % sign does is It will instruct the compiler that that the value coming after the mod % is to be replaced with the empty reserved space.