Home  >  Article  >  Backend Development  >  How does python divide sentence chunks?

How does python divide sentence chunks?

藏色散人
藏色散人Original
2019-11-05 11:14:524006browse

How does python divide sentence chunks?

How does python divide sentence blocks?

Python divides sentence blocks in indentation format.

Open the editor here and create a new py file as a demonstration.

Recommended: "python tutorial"

How does python divide sentence chunks?

def happy():
    print("Very Happy!")
happy()

When creating a function, you need to indent after the colon to mark the statement block.

How does python divide sentence chunks?

x = 1
while x < 5:
    print(x)
    x += 1

When using while, you need to indent after the colon to mark the statement block.

How does python divide sentence chunks?

x = 1
if x < 10:
    print("ok")
else:
    print("not ok")

When using if and else statements, they need to be indented after the colon to mark the statement block.

How does python divide sentence chunks?

If you do not mark the statement block, an error will be reported.

How does python divide sentence chunks?

def hey():
    x = 1
    while x < 3:
        print("hey")
        x += 1
        if x == 3:
            print("ok")
hey()

After each colon, a statement block needs to be marked, and it must be marked layer by layer according to the format.

How does python divide sentence chunks?

The above is the detailed content of How does python divide sentence chunks?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn