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.
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.
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.
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.
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.
print() function example
There are some functions which are probably used in print().
- sep="seperator"
- end="end"
Top comments (0)