kqij
V2EX  ›  问与答

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

  •  
  •   kqij · May 25, 2014 · 4852 views
    This topic created in 4369 days ago, the information mentioned may be changed or developed.
    为什么用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()
    2 replies    2014-05-25 18:48:03 +08:00
    Sylv
        1
    Sylv  
       May 25, 2014 via iPhone
    就是缩进错误,你贴的代码没缩进没法差错
    请检查每行的缩进是否正确,有没混用空格和 tab,空格数是不是一致
    Sylv
        2
    Sylv  
       May 25, 2014 via iPhone   ❤️ 1
    估计你是根本就没缩进
    缩进是 Python 语法的一部分,请照着书在每行加入合适的缩进,缩进推荐用4个空格
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1079 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:55 · PVG 06:55 · LAX 15:55 · JFK 18:55
    ♥ Do have faith in what you're doing.