0
I want to print the value of x along with a string in the print statement. please help me with this
I want to print the value of x along with a string in the print statement. please help me with this. int x=100; print(x +"is your value"); output should be " 100 is your value"
6 Respostas
+ 5
For simple cases like this a comma will do.
But if you have a more variable-packed string to print, you can use Python string formatting, save you a lot on code clarity :)
You can check an example on my "1000 robots" code 🤖
https://code.sololearn.com/cwjsOELw9656/?ref=app
+ 5
#with printf style formatting
x=100;print("%d is your value" % x)
+ 4
#just a comma would do the trick
x=100;print(x,'is your value')
+ 1
x=100
print(x," is your value")
output: 100 is your value
0
Space between the + and " maybe?
0
thanks hamletmun and Tom. print(x,'is your value') works.