0

Doubt in python (variable)

Can anyone tell me how in python we can use variable so that when we print the variable appears. Like(i do this):- variable="python" Print("I like using variable")

29th May 2025, 2:44 PM
Vivanshi Agarwal
Vivanshi Agarwal - avatar
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}")
29th May 2025, 3:14 PM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 3
Vivanshi Agarwal In addition to Afnan Irtesum Chowdhury you can also use:- print("I like using {0}".format(variable))
29th May 2025, 3:29 PM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 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.
30th May 2025, 3:49 AM
Ushasi Bhattacharya