0

我本身不是 Pythonista 专家,所以我将首先澄清一下,关于我遇到的 else 语句问题,什么可能被认为是一个微不足道的问题。无论如何,为了简洁起见,我在stackoverflow上查看了所有关于相同/相似问题的其他语法问题,但我仍然无法解决问题。这是有问题的代码块:

   else: 
        m_len -= 33 
        dst.append(32) 
        n, m_len = divmod(m_len, 255) 
        dst.extend("\x00" * n) 
        dst.append(m_len) 
        dst.append((m_off << 2) & 0xff) 
        dst.append((m_off >> 6) & 0xff)
   else: #This is the line being complained about
        m_off -= 0x4000 
   if m_len <= 9: 
        dst.append(0xff & (16 | ((m_off >> 11) & 8) | (m_len - 2)))

提前感谢您提供的任何帮助或建议!干杯!

4

2 回答 2

5

一个条件块中不能有多个else语句
将第一个语句更改elseelif并指定一些条件

于 2012-10-16T02:08:32.897 回答
1

你的条件必须是这样的:

if (condition):#the program can choose as many "if" as many you put in your program (in theory)
 ..code..
#here you can add as many "if" as you want
elif (condition):#the program will only choose one block you must have a "if" block before
 ..code..
#here again you can add as many "elif" as you want
else:#before "else" you must have a if block before
 ..code..
#here only one "else"

你认为程序如何选择else或else?!哈哈

于 2012-10-16T10:47:19.377 回答