poniedziałek, 4 stycznia 2016

Formated output in python

import time
'''simple multiplication'''

def drawline(l):
    print(l * "-=-")


def main():
    start = time.time()
    for x in xrange(10):
        for y in xrange(10):
            print("x %d * y %d = res %d" % (x,y,x*y))
    end = time.time()

    print(end - start)


if __name__ == "__main__":
    main()

Conversion Meaning
d Signed integer decimal.
i Signed integer decimal.
o Unsigned octal.
u Unsigned decimal.
x Unsigned hexadecimal (lowercase).
X Unsigned hexadecimal (uppercase).
e Floating point exponential format (lowercase).
E Floating point exponential format (uppercase).
f Floating point decimal format.
F Floating point decimal format.
g Same as "e" if exponent is greater than -4 or less than precision, "f" otherwise.
G Same as "E" if exponent is greater than -4 or less than precision, "F" otherwise.
c Single character (accepts integer or single character string).
r String (converts any python object using repr()).
s String (converts any python object using str()).
% No argument is converted, results in a "%" character in the result

Brak komentarzy:

Prześlij komentarz