3 Antworten
+ 5
You can either use f-string or string concatenation.
Assuming variable is declared and initialized,
Both of these work:
print("I like using " + variable)
print(f"I like using {variable}")
+ 3
Vivanshi Agarwal
In addition to Afnan Irtesum Chowdhury you can also use:-
print("I like using {0}".format(variable))
+ 2
Vivanshi Agarwal , you can also use:
print('I like using', variable)
# The comma (,) adds a white space by default.
See, (if you are interested in finding out what was wrong with your argument) the print() function displays the argument you give it inside the brackets (....) on the console.
If you write something within quotes("..." or '...'), doesn't matter if it is a keyword or a variable name,it is treated and hence, displayed as a string as it is. The 'variable' in your argument has become a string and thus, the computer does not take the value assigned to it.