1 print('Chris' + 2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-82ccfdd3d5d3> in <module>()
----> 1 print('Chris' + 2)

TypeError: must be str, not int

print('Chris' + str(2))
Chris2

字符串的格式设置 
1
sales_record = { 2 'price': 3.24, 3 'num_items': 4, 4 'person': 'Chris'} 5 6 sales_statement = '{} bought {} item(s) at a price of {} each for a total of {}' 7 8 print(sales_statement.format(sales_record['person'], 9 sales_record['num_items'], 10 sales_record['price'], 11 sales_record['num_items']*sales_record['price']))
Chris bought 4 item(s) at a price of 3.24 each for a total of 12.96




 
posted on 2018-03-05 19:32  郑哲  阅读(111)  评论(0编辑  收藏  举报