鱼C论坛

 找回密码
 立即注册
查看: 747|回复: 2

[已解决]python 语法

[复制链接]
发表于 2019-4-29 16:38:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
'The {1} is {0:%d}, the {2} is {0:%B}.'.format(d, "day", "month"),这个该怎么理解呢,{1}代表什么?
最佳答案
2019-4-29 17:13:55
个人推测应该是如下:
'The {1} is {0:d}, the {2} is {0:d}.'.format(d, "day", "month")
如果是这样,{0}代表d,{1}代表day,  {2}代表month,
为什么会这样,可以了解下format,简单说是如下:
前方0、1、2对应后面的各元素
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-4-29 16:46:27 | 显示全部楼层
你这个是不对得

假设d=25

>>> s='The {0:d} is , the {1:s} is {2:s}.'.format(d, "day", "month")
>>> print (s)
The 25 is , the day is month.
>>> s='The {0} is , the {0} is {2}.'.format(d, "day", "month")
>>> print (s)
The 25 is , the 25 is month.
>>>
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-4-29 17:13:55 From FishC Mobile | 显示全部楼层    本楼为最佳答案   
个人推测应该是如下:
'The {1} is {0:d}, the {2} is {0:d}.'.format(d, "day", "month")
如果是这样,{0}代表d,{1}代表day,  {2}代表month,
为什么会这样,可以了解下format,简单说是如下:
前方0、1、2对应后面的各元素
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-16 02:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表