If statement in Python with Example

Updated: Feb 16


If statements are control flow statements and it is run a particular code only when a condition is satisfied. It means that to print a message or result on the screen only when a condition is true and it condition is false then it is not print a message or result on screen. if..else, if..elif..else are other control flow statements available in Python.


Syntax:

if condition:

statement


Example:

a = True

if a==True:

print("Welcome")

print("To")

print("Career Bodh Sansthan")


Output:

Welcome

To

Career Bodh Sansthan

Example2:

a=10

if a>0:

print("Positive Number")

Output:

Positive Number

Example2:

a=-10

if a>0:

print("Positive Number")

Output:

No result on screen


11 views0 comments

Recent Posts

See All

Tell () function can be used to get the position of file handle and returns current position of file object where as Seek () function is used to change the position of the file handle to a given speci

Seek () function is used to change the position of the file handle to a given specific position in python. File handle such as a cursor which defines from where the data has to be read or written in t

Slicing is a Python attitude that enables accessing parts of data from the given sequence like list, tuples etc. A slice object is created based on a set of indices. Slicing starts anywhere from list