官术网_书友最值得收藏!

Multiple line spanning

Statements can span more than one line if they are collected within braces (parentheses (), square brackets [], or curly braces {}). Normally parentheses are used. When spanning lines within braces, indentation doesn't matter; the indentation of the initial bracket is used to determine which code section the whole statement belongs to. The following example shows a single variable having to span multiple lines due to the length of the parameters:

tank1 = tank.Tank(
"Tank 1",
level=36.0,
fluid_density=DENSITY,
spec_gravity=SPEC_GRAVITY,
outlet_diam=16,
outlet_slope=0.25
)

tank1 is the variable, and everything to the right of the equal sign is assigned to tank1. While Python allows the developer to write everything within the parentheses on one line, the preceding example has separated each parameter into different lines for clarity.

The Python interpreter recognizes that everything within the parentheses is part of the same object (tank1), so spreading the parameters across multiple lines doesn't cause a problem.

String statements (text) can also be multiline if you use triple quotes. For example, the following screenshot demonstrates a long block of text that is spread over multiple lines:

Triple quote line spanning

When the variable containing the text is directly called (line 10 in the preceding screenshot), Python returns the raw text, including the \n symbol which represents a newline character; it tells the system where a new line starts and the old one ends. However, when the print() function is called in line 11, the text is printed as it was originally entered.

主站蜘蛛池模板: 兴隆县| 宁化县| 洱源县| 高陵县| 大关县| 房山区| 秭归县| 闽清县| 乌鲁木齐市| 威信县| 江都市| 德格县| 明溪县| 永兴县| 江阴市| 左贡县| 邓州市| 嵩明县| 运城市| 莱州市| 万源市| 鄯善县| 南阳市| 宜丰县| 两当县| 灵寿县| 安平县| 嵊泗县| 金湖县| 明溪县| 大洼县| 呼伦贝尔市| 金坛市| 平定县| 三都| 澳门| 永新县| 宁乡县| 会东县| 金门县| 大兴区|