Page 479 - ComputerScience_Class_11
P. 479

There are three main types of statements in Python:
                 •  Simple Statements                       • Multiline Statements           • Multiple Statements

                 12.4.1 Simple Statement
                 A simple statement in Python is a statement that is written in a single line and completed by pressing the Enter key.
                 Each simple statement performs one action and is written on a new line.
                 Program 12: To demonstrate simple statements in Python.

                     Program 12.py

                  File  Edit  Format   Run   Options   Window     Help

                  # Simple assignment statements
                  a = 5
                  b = 10
                  # Simple arithmetic statement
                  c = a + b
                  # Simple output statement
                  print("Value of a:", a)
                  print("Value of b:", b)
                  print("Sum of a and b:", c)



                     Output

                  Value of a: 5
                  Value of b: 10
                  Sum of a and b: 15




                 12.4.2 Multiline Statement
                 A multiline statement is a statement that is written across two or more lines instead of a single line. It is used when the
                 code is too long to fit comfortably on one line. Multiline statements make the program more readable and organized.
                 Python allows multiline statements in the following ways:
                 •  The line continuation character (\)

                 •  Brackets such as (), [], {}
                 Program 13: To demonstrate multiline statement.

                     Program 13.py
                  File  Edit  Format   Run   Options   Window     Help

                  # Performing a long addition using line continuation character (\)
                  result = 100 + 200 + 300 + \
                           400 + 500 + 600
                  # Displaying the final result
                  print("Result:", result)




                     Output

                  Result: 2100





                                                                                           Operators and Expressions  477
   474   475   476   477   478   479   480   481   482   483   484