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"

3rd Sep 2017, 3:56 PM
Sashank Reddy
Sashank Reddy - avatar
6 Antworten
+ 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
3rd Sep 2017, 8:03 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
#with printf style formatting x=100;print("%d is your value" % x)
3rd Sep 2017, 10:57 PM
hamletmun
hamletmun - avatar
+ 4
#just a comma would do the trick x=100;print(x,'is your value')
3rd Sep 2017, 4:57 PM
hamletmun
hamletmun - avatar
+ 1
x=100 print(x," is your value") output: 100 is your value
4th Sep 2017, 6:22 PM
Ramsuraj Yadav
Ramsuraj Yadav - avatar
0
Space between the + and " maybe?
3rd Sep 2017, 4:43 PM
Tom
Tom - avatar
0
thanks hamletmun and Tom. print(x,'is your value') works.
3rd Sep 2017, 5:00 PM
Sashank Reddy
Sashank Reddy - avatar