Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
if condition

How to execute an If statement in Python

Educative Answers Team

What is an if statement?

A computer program often requires a decision or a branch within a code to account for how the code operates under different inputs or conditions.

Within the Python programming language, the simplest and sometimes the most useful way of creating a branch within your program is through an if statement.

Syntax

The syntax for writing an if statement is as follows:

Code

Let’s take a look at an example implementing an if statement:

#creating variables "a" and "b"
a = 500
b = 200

#if condition to check whether "a" is greater than "b"
if(a > b):
  print "a is greater than b"  

The illustration below explains the code above.

Flowchart of if statement
1 of 4

RELATED TAGS

python
if condition
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring