DEV Community

mahdin1209
mahdin1209

Posted on

INTRODUCTION PART 2

Today we are going to learn about some basics of python like indentation and branching.

Indentation

So, first of all indentation refers to the spaces at the beginning of a code line. It mainly indicates a block of code. A code block (body of a condition, loop, function etc) starts with indentation and ends with the first unintended line. In python indentation is very important as it will give you an error if you skip the indentation.

Image description

Image description

Branching

Python programming language provides following types of decision making or branching statements in Python. Python programming language provided decision making statements or branching statements as follows.

  • if statements

  • if...else statements

  • if....elif....else statements

  • nested if statements

if statements
It is used to decide whether a certain statement or block of statements will be executed or not. If a certain condition is true, then a block of statement is executed otherwise not.
Image description
if...else statements
The else statement is always used with if statement. It is used to execute block of codes whenever if condition gives false result.
Image description
if...elif...else statements
For adding more conditions, elif statement in used. The program first checks if condition. When found false, it checks elif conditions. If all elif conditions are found false, then else code block is executed.

Image description

nested if statements
A nested if statement is an if statement placed inside another if statement. In a nested if construct, you can have an if...elif...else construct inside another if...elif...else construct.

Image description

print() function example

There are some functions which are probably used in print().

  1. sep="seperator" Image description
  2. end="end" Image description

Top comments (0)