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.

  1. variable = "7" 
  2. string= "The value of variable = %s"%variable 
  3. print(string) 
  4. variable = int(variable) 
  5. string = "The value of variable is = %d"%variable 
  6. print(string) 
  7. string = "The value of variable is =%x"%x 
  8. print(string) 

Comments

Popular posts from this blog

Programmingshark index 6

Proassignmenthelp index 12

Proassignmenthelp index 27