博客
关于我
python %ns的作用
阅读量:806 次
发布时间:2023-03-05

本文共 218 字,大约阅读时间需要 1 分钟。

在Python中,格式化字符串中的%3s占据了3个字符的位置。如果要打印的字符串长度少于3个字符,会在前面补充空格;如果多于3个字符,则会按实际字符串的长度打印。例如:

print('%3s' % 'ab')  # 输出: ab  print('%3s' % 'abc') # 输出: abc  print('%3s' % 'abcd') # 输出: abcd

这意味着,%3s格式化符号不会截断字符串,而是根据实际内容占据相应的空间。

转载地址:http://wiafk.baihongyu.com/

你可能感兴趣的文章
python课程的中期报告范文_课题研究中期总结报告范文
查看>>
python | lxml,一个超酷的 关于XML/HTML 文档 Python 库!
查看>>
python | mplfinance,一个有趣的金融数据可视化 Python 库!
查看>>
python | nipy,一个强大的关于 神经影像数据分析 的Python 库!
查看>>
python | NLTK,一个强大的 自然语言处理 Python 库!
查看>>
python | nupic,一个强大的 处理时间序列的Python 库!
查看>>
python | orange3,一个神奇的 Python 库!
查看>>
python | pdfminer,一个神奇的 关于PDF 文件的 Python 库!
查看>>
python | pendulum,一个有趣的 日期和时间 Python 库!
查看>>
python | pluginbase,一个神奇的 关于插件框架 的Python 库!
查看>>
python | ply,一个无敌的 词法和语法分析工具 的Python 库!
查看>>
python | py2exe,一个超酷的 Python 库!
查看>>
python | pyautogui,一个超酷的 Python 库!
查看>>
python | pybaobabdt,一个超强的 决策树可视化 Python 库!
查看>>
python | pycco,一个神奇的 Python 库!
查看>>
python | pyg2plot,一个有趣的 数据可视化 Python 库!
查看>>
python | pymc,一个超强的 Python 库!
查看>>
python | pynsist,一个强大的 Python 库!
查看>>
python | pyparsing,一个强大的 Python 库!
查看>>
python | pyqtgraph,一个神奇的 Python 库!
查看>>