2024-10-03 09:09:30 发布
网友
我试图用一个循环来格式化字符串文件名这是我的代码
for i in range(1, 16): bgImageFile = ("bg_%01.png" %i)
语法要求%d(或%s),而不仅仅是%:
%d
%s
%
for i in range(1, 4): bgImageFile = 'bg_%s01.png'%i print(bgImageFile) bg_101.png bg_201.png bg_301.png
在python3.6+中,可以使用f-strings(PEP498):
{你应该知道一些^说明符:
%s - String (or any object with a string representation, like numbers)%d - Integers%f - Floating point numbers%.<number of digits>f - Floating point with fixed amount of digits to the right of the dot.%x/%X - Integers in hex representation (lowercase/uppercase)
%s - String (or any object with a string representation, like numbers)
%d - Integers
%f - Floating point numbers
%f
%.<number of digits>f - Floating point with fixed amount of digits to the right of the dot.
%.<number of digits>f
%x/%X - Integers in hex representation (lowercase/uppercase)
%x/%X
语法要求
%d
(或%s
),而不仅仅是%
:在python3.6+中,可以使用f-strings(PEP498):
^{pr2}${你应该知道一些^说明符:
相关问题 更多 >
编程相关推荐