Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of f-Strings in Python

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the use of f-Strings in Python, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1. Variable name str_value = "hello,python coders" print (f "{str_value =}") # str_value = 'hello Python coders'2, directly change the output num_value = 123print (f "{num_value% 2 =}") # num_value% 2 = 13, direct format date import datetime today = datetime.date.today () print (f "{today:% Y%m%d}") # 20211019 print (f "{today =:% Y%m%d}") # today = 202110194, The 2-8-16 binary output is really too simple > a = 42 > f "{avision b}" # 2 base '101010' > > f "{abureo}" # 8 base'52'> > f "{avision x}" # 16 base Lowercase letter'2a'> > f "{av X}" # hexadecimal Uppercase letters'2A'> > f "{ascii}" # ascii code'*'5, formatted floating point number > > num_value = 123.456 > f' {num_value =: .2f}'# keep 2 decimal places' num_value = 123.46'> nested_format = ".2f" # can be used as a variable > print (f'{num_value: {nested_format}') 123.466, String alignment > x = 'test' > f' {x: > 10}' # right alignment Fill in the blanks on the left 'test' > f' {XRV *

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report