相关疑难解决方法(0)

如何在Python中进行换行(换行)?

我有一长串代码,我希望在多行之间分解.我使用什么,语法是什么?

例如,添加一串字符串,

e = 'a' + 'b' + 'c' + 'd'
Run Code Online (Sandbox Code Playgroud)

并将它分成两行:

e = 'a' + 'b' +
    'c' + 'd'
Run Code Online (Sandbox Code Playgroud)

python syntax line-breaks long-lines

979
推荐指数
9
解决办法
144万
查看次数

有效语句中的"SyntaxError:无效语法"

我在我的代码中添加了一个elif语句:

    if i % 100 < 10:
        letter_count += numletters[str(i)[len(str(i)) - 1]
    elif (i % 100 >= 10) and (i % 100 < 20):
        letter_count += numletters[str(i)[len(str(i)) - 2:]]
Run Code Online (Sandbox Code Playgroud)

现在它给了我一个语法错误:

File "<stdin>", line 35
    elif (i % 100 >= 10) and (i % 100 < 20):
       ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我不知道该声明有什么问题,在此先感谢您的帮助.

python-3.x

2
推荐指数
1
解决办法
2570
查看次数

标签 统计

line-breaks ×1

long-lines ×1

python ×1

python-3.x ×1

syntax ×1