Skip to content
Home » Single Statement Suites in Python

Single Statement Suites in Python

Spread the love

Today we’ll be talking about single statement suites.

If the suite (block of code) following the if, for or while statement consists only of one line of code, we can place it on the same line as the statement, immediately after the colon:

 >>> if 2 + 2 == 4 : print("Yes")
 ... 
 Yes 

The following code falls into an infinite loop, so you’d better not run it. Instead of writing:

 number = 1
 while number == 1: 
     print(number) 

you could write:

 number = 1
 while number == 1: print(number) 

Here’s an example with a for loop:

 for iin range(5) : print(i) 

Your Panda3D Magazine

Make Awesome Games and Other 3D Apps

with Panda3D and Blender using Python.

Cool stuff, easy to follow articles.

Get the magazine here (PDF).

Python Jumpstart Course

Learn the basics of Python, including OOP.

with lots of exercises, easy to follow

The course is available on Udemy.

Blender Jumpstart Course

Learn the basics of 3D modeling in Blender.

step-by-step, easy to follow, visually rich

The course is available on Udemy and on Skillshare.


Spread the love

Leave a Reply