티스토리 뷰

Python

String Width and Precision

techbard 2016.06.04 00:27

# Width and Precision


# d1 = '%5d' % -10

# print(d1)


# d2 = '%5d' % 10

# print(d2)


# dd = '%05d' % -10

# print(dd)



# s = '%.*s' % (3, 'apple')

# print(s)


# from math import pi


# pp = '[%010.2f]' % pi

# print(pp)


# pp2 = '[%-10.2f]' % pi

# print(pp2)



# p = '[%9f]' % pi

# print(p)


# p = '[%5.2f]' % pi

# print(p)


# p = '[%.2f]' % pi

# print(p)


# p = '[%0.2f]' % pi

# print(p)



# priceOfHam = 'Price of ham: $%d' % 42

# print(priceOfHam)



# s = '%s plus %s equals %s' %(1, 1, 2)


# print(s)




# p = "Pi with three decimal: %0.3f"


# from math import pi

# print(p % pi)



댓글
댓글쓰기 폼
공지사항
Total
409,801
Today
19
Yesterday
27
«   2019/11   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함