13 RĂ©ponses
+ 6
I prefere the f- string mentioned by HonFu, but also with a simple print statement and without any conversion you can do that:
num = 7
print("Square of" ,num, "is", num**2)
So instead of using "+" as an operator for concatenation use "comma" to "merge" string and numerical information. This will be done implicitly by print function.
+ 5
Lothar
I your answer is helpful
Thanks Bro
+ 4
Thanks bro for helping me
+ 3
You can also use a format string:
print(f'Square of {num} is {num**2}')
+ 2
and at second place where num**2 is written
+ 2
#In simple way:
print("Square of",num,"is",num**2)
# str():
print("Square of " + str(num) + " is " + str(num**2))
# format1:
print(f"Square of {num} is {num**2}")
# format2:
print("Square of {} is {}".format(num, num**2))
# format3:
print("Square of %i is %i" %(num, num**2))
+ 1
Use format
Or f string
0
Just use str(variable)
0
Solution Of Your Question Is :
print(âSquare Ofâ,num,âisâ,num**2)
0
print("Square of" +str(num)+"is"+str(num**2))
0
print("Square of %d is %d" %(num,num**2))
- 1
Better Use f String Method This Will Help You Alot.
x=2
square=pow(x,2)
print(fâ Square Of {x} Is : {square}â)