gpt4 book ai didi

python - 如何评论运算符之间的大赋值?

转载 作者:太空宇宙 更新时间:2023-11-04 06:55:24 25 4
gpt4 key购买 nike

fontName  = b"\xC8\xC1\x10" \
# Representación del tipo de fuente en bytes.
+ fontNamesInBytes[fontName] \
# Tipo de atributo: attr_ubyte | Atributo: FontName (Nº 168)
+ "\xF8\xA8"

python3 test.py
File "test.py", line 14
+ fontNamesInBytes[fontName] \
^
IndentationError: unexpected indent

python3 test.py
File "test.py", line 13
\# Representación del tipo de fuente en bytes.\
^
SyntaxError: unexpected character after line continuation character

python3 test.py
File "test.py", line 15
""" Tipo de atributo: attr_ubyte | Atributo: FontName (Nº 168)"""\
^
SyntaxError: invalid syntax

我可以在作业之间发表评论吗?我试过 """""" 但也给出了语法错误。

为 Martin 编辑:

fontName  = b"\xC8\xC1\x10" \
""" Representación del tipo de fuente en bytes."""\
+ fontNamesInBytes[fontName] \
""" Tipo de atributo: attr_ubyte | Atributo: FontName (Nº 168) """\
+ b"\xF8\xA8"

    python3 test.py
File "test.py", line 15
""" Tipo de atributo: attr_ubyte | Atributo: FontName (Nº 168) """\
^
SyntaxError: invalid syntax

最佳答案

你可以做到

In [5]: ('a'
...: # comment
...: 'b')
Out[5]: 'ab'

你的代码会变成

fontName  = (b"\xC8\xC1\x10" 
# Representación del tipo de fuente en bytes.
+ fontNamesInBytes[fontName] +
# Tipo de atributo: attr_ubyte | Atributo: FontName (Nº 168)
b"\xF8\xA8")

这是有效的,因为括号、方括号或大括号中的表达式可以在不使用反斜杠的情况下拆分为多个物理行隐式续行可以携带注释(根据到 documentation )。

关于python - 如何评论运算符之间的大赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25429055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com