Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
name = 'Huahua' score = 123.456789 print('name = ' + name + ', score = ' + str(score)) print('name = %s, score = %.3f' % (name, score)) print('name = {name}, score = {score:.3f}'.format(name=name, score=score)) print('name = {name}, score = {score:.3f}'.format(name='Huahua', score=123.456789)) print(f'name = {name}, score = {score:.3f}') # Python 3.6 print(f'{name = }, {score = :.3f}') # Python 3.8 def add(a, b): return a + b k = 1 print(f'{k = }, {add(k, 2) = }') # k = 1, add(k, 2) = 3 |
请尊重作者的劳动成果,转载请注明出处!花花保留对文章/视频的所有权利。
如果您喜欢这篇文章/视频,欢迎您捐赠花花。
If you like my articles / videos, donations are welcome.
Be First to Comment