admin管理员组

文章数量:1530842

2024年4月23日发(作者:)

15 >>>

3、字符串输出

%s

%10s——右对齐,占位符10位

%-10s——左对齐,占位符10位

%.2s——截取2位字符串

%10.2s——10位占位符,截取两位字符串

1 >>> print('%s' % 'hello world') # 字符串输出

2 hello world

3 >>> print('%20s' % 'hello world') # 右对齐,取20位,不够则补位

4 hello world

5 >>> print('%-20s' % 'hello world') # 左对齐,取20位,不够则补位

6 hello world

7 >>> print('%.2s' % 'hello world') # 取2位

8 he

9 >>> print('%10.2s' % 'hello world') # 右对齐,取2位

10 he

11 >>> print('%-10.2s' % 'hello world') # 左对齐,取2位

12 he

4、 其他

(1)字符串格式代码

本文标签: 字符串输出用法截取补位