极乐门资源网 Design By www.ioogu.com
运行的时候,有时候会出现语法错误: IndentationError: unexpected indent
可以用如下方法解决:
首先把空格显示出来,空格的地方 ,由点代替
修改把tab 代表4个位置
然后格式就对齐了。
实例扩展:
如何解决文本对齐
大家好,我是python学习新手,我在一个练习题目中遇到问题.
题目的要求是把列表打印输出并对齐。
输入数据:
tableData = [['apples', 'oranges', 'cherries', 'banana'], ['Alice', 'Bob', 'Carol', 'David'], ['dogs', 'cats', 'moose', 'goose']]
要求的输出数据(第一行右对齐,其他左对齐):
apples Alice dogs oranges Bob cats cherries Carol moose banana David goose
以下是我的代码
"""下面是代码正文""" tableData = [['apples', 'oranges', 'cherries', 'banana'], ['Alice', 'Bob', 'Carol', 'David'], ['dogs', 'cats', 'moose', 'goose']] def printTable(tableData): # 下面是为了求每个内层列表的最长字符串的长度 colWidths = [0] * len(tableData) for i in range(len(colWidths)): colWidths[i] = len(sorted(tableData[i], key=(lambda x: len(x)))[-1]) for x in range(len(tableData[0])): for y in range(len(tableData)): print(tableData[y][x].rjust(colWidths[y]), end=' ') print('') # 换行 printTable(tableData)
输出结果是(全部右对齐了):
apples Alice dogs oranges Bob cats cherries Carol moose banana David goose
标签:
python,对齐错误
极乐门资源网 Design By www.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无解决python对齐错误的方法的评论...
更新日志
2024年09月20日
2024年09月20日
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 《末日地带2》评测:酣畅淋漓的“和面”之旅
- 萧煌奇《没事的》[320K/MP3][96.22MB]
- 萧煌奇《没事的》[FLAC/分轨][263.38MB]
- 群星《音你而来 第6期》[320K/MP3][90.61MB]
- 交错战线爬塔攻略一览
- 战锤40K星际战士2全近战武器使用教学|近战武器连招表