learn python the hard way 第三版是否不适用于 Python 2.7 版本?

2014-05-25 18:28:08 +08:00
 kqij
为什么用notepad++运行以下代码时出错,
显示IndentationError: expected an indented block ,
它停留在第三行里,我百度过,听说与空格有关,
百思不得其解,遂请教于诸君。
# this one is like your scripts with argv
def print_two(*args):
arg1 , arg2 = args
print "arg1: %r, arg2: %r" % (arg1, arg2)
# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
print "arg1: %r, arg2: %r" % (arg1, arg2)
# this just takes one argument
def print_one(arg1):
print "arg1: %r" % arg1
# this one takes no arguments
def print_none():
print "I got nothin'."
print_two("Zed","Shaw")
print_two_again("Zed","Shaw")
print_one("First!")
print_none()
4267 次点击
所在节点    问与答
2 条回复
Sylv
2014-05-25 18:44:15 +08:00
就是缩进错误,你贴的代码没缩进没法差错
请检查每行的缩进是否正确,有没混用空格和 tab,空格数是不是一致
Sylv
2014-05-25 18:48:03 +08:00
估计你是根本就没缩进
缩进是 Python 语法的一部分,请照着书在每行加入合适的缩进,缩进推荐用4个空格

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/114191

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX