打印空行? [英] Print empty line?

查看:101
本文介绍了打印空行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注Python的初学者教程,这里有一个小练习,我必须添加一个额外的函数调用并在经文之间打印一行,如果我在函数调用之间打印一条空行,但如果我添加了该行,这会很好happyBirthday()末尾的空白打印行出现缩进错误,但是没有添加所有打印行都可以正常工作,有关为什么的任何建议?

I am following a beginners tutorial on Python, there is a small exercise where I have to add an extra function call and print a line between verses, this works fine if I print an empty line in between function calls but if I add an empty print line to the end of my happyBirthday() I get an indent error, without the added print line all works fine though, any suggestions as to why?

这是代码:

def happyBirthday(person):
    print("Happy Birthday to you!")
    print("Happy Birthday to you!")
    print("Happy Birthday, dear " + person + ".")
    print("Happy Birthday to you!")
    print("\n") #error line

happyBirthday('Emily')
happyBirthday('Andre')
happyBirthday('Maria')

推荐答案

只有在确实存在缩进错误的情况下,您才会始终得到缩进错误.仔细检查您的最后一行是否缩进与其他行相同-带有空格或制表符.最有可能的是,其中一些行带有空格(或制表符),而另一行则带有制表符(或空格).

You will always only get an indent error if there is actually an indent error. Double check that your final line is indented the same was as the other lines -- either with spaces or with tabs. Most likely, some of the lines had spaces (or tabs) and the other line had tabs (or spaces).

信任错误消息-如果它说的是某些特定内容,请假定它是正确的,并找出原因.

Trust in the error message -- if it says something specific, assume it to be true and figure out why.

这篇关于打印空行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆