string formatting in Python
string formatting in Python
a string of required formatting can be obtain by different methods like :-
%d – integer
%f – float
%s – string
%x – hexadecimal
%o – octal
The below example describes the use of formatting using % in Python.
- variable = "7"
- string= "The value of variable = %s"%variable
- print(string)
- variable = int(variable)
- string = "The value of variable is = %d"%variable
- print(string)
- string = "The value of variable is =%x"%x
- print(string)
Comments
Post a Comment