# -*- coding: utf-8 -*- # 3.0 # fp = 3.4 complex = 3+4j # print "%f"%(fp) # print "%f, %f"%(fp, complex) # print "%f, %f+%fj"%(fp, complex.real, complex.imag) # # But what if you don't know what kind of object you need to format in your string? # print "%s"%("The string formatter") # # works for anything... "%s, %s"%(fp, complex) # # What it does is call the __str__ method on the object. # # There is also "%r" which calls the __repr__ method. # "%r, %r"%(fp, complex) # class test(object): def __str__(self): return "This is the ouput of the __str__ method" def __repr__(self): return "This is the ouput of the __repr__ method" # t = test() "%s"%t # "%r"%t #