请问老师这个样怎么解决
还有0人有此问题
发表在Python视频课程答疑 2020-03-04
是否精华
版块置顶:

QQ截图20200304204257.jpg

 请问我这个出发时间、到达时间和历时无法跟下面的对齐?

2020-03-04 20:46:21编辑
分享到:
精彩评论 3
lkhight
学分:665 LV6
2020-03-04
沙发

得看一下你的代码是如何控制输出格式的

黎小贤
学分:443 LV5
2020-03-04
板凳

lkhight 发表于2020-03-04 20:55

得看一下你的代码是如何控制输出格式的

lieche=["车次","出发站—到达站","出发时间","到达时间","历时",
        "T40","长春—北京","00:12","12:20","12:08",
        "T298","长春—北京","00:06","10:50","10:44",
        "Z158","长春—北京","12:48","21:06","08:18",
        "Z62","长春—北京","21:58","06:08","08:20"]
for index,s in enumerate(lieche):
    if (index+1) % 5 == 0:
        print(s)
    else:
        print(s , "\t\t" , end=' ')

请大神指教

lkhight
学分:665 LV6
2020-03-05
地板

黎小贤 发表于2020-03-04 21:01

lieche=["车次","出发站—到达站","出发时间","到达时间","历时",
        "T40","长春—北京","00:12","12:20","12:08",
        "T298","长春—北京","00:06","10:50","10:44",
        "Z158","长春—北京","12:48","21:06","08:18",
        "Z62","长春—北京","21:58","06:08","08:20"]
for index,s in enumerate(lieche):
    if (index+1) % 5 == 0:
        print(s)
    else:
        print(s , "\t\t" , end=' ')

请大神指教

太图省事了 \t只是单纯补空格 ljust printf的format这些函数还是制表函数repr用上 查api照着用就可以
首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照