Skip to playerSkip to main contentSkip to footer
  • 5/18/2025
if, elif, and else statements are used to control the flow of execution in a Python program based on specified conditions.
Basic if Statement
The if statement evaluates a condition. If the condition is True, the block of code indented below the if statement is executed. If the condition is False, the block is skipped.

Category

📚
Learning
Transcript
00:00I have a short introduction. I have said that we will talk about conditional.
00:04I will go back to you and start talking about the code.
00:09What we have written about code and how we have written about code,
00:13the execution of code was like this.
00:16Let's say line 3 on the code was executed.
00:21Next line 4th, 5th, 6th, 7th and execute.
00:27This is a to b.
00:31However, we have no mechanism.
00:36We have no mechanism.
00:39We have no mechanism.
00:41We have no mechanism.
00:43We have no ability.
00:55We have no decision on the condition.
01:00We have no mechanism.
01:02We have no mechanism.
01:04We have no mechanism.
01:06Of course, you have no mechanism.
01:08We have no mechanism.
01:10We have no mechanism.
01:12We have no mechanism.
01:14and point B
01:16up here
01:17and point B
01:18up here
01:19one is
01:21the way to C
01:22and the way to D
01:23are
01:24two
01:25now
01:26you are here
01:28and this
01:29place
01:30and this
01:31place
01:32you have a
01:33look at this
01:34like this
01:35one is
01:36a
01:37look at this
01:38and
01:39tell you
01:40that
01:41you have a
01:42condition
01:43or a
01:44safe
01:45D
01:46then
01:47you have a decision
01:49depending on
01:51condition
01:52on
01:53this
01:54whole code
01:55and this
01:56whole
01:57path
01:58and this
01:59is
02:00this
02:01code
02:02exists
02:03however
02:04it will skip
02:05depending on
02:06the condition
02:07now
02:08this
02:09example
02:10this
02:11is
02:12already
02:13code
02:14basically
02:15linear fashion
02:16move
02:17now
02:18we
02:19have
02:20read
02:21true
02:22and false
02:23and here
02:24false
02:25here
02:26now
02:27we
02:28have
02:29if
02:30keyword
02:31if
02:32this
02:33is
02:34what
02:35condition
02:36is
02:37what
02:38condition
02:39if
02:40condition
02:41if
02:42then
02:43print
02:44move
02:45left
02:46move
02:47move
02:48left
02:49thing
02:51however
02:52boot
02:53built
02:54in
02:55python
02:56is
02:57that
02:58python
02:59has
03:00been
03:01this
03:02thing
03:03this
03:04is
03:05what
03:06this
03:07is
03:08that
03:09we
03:10basically
03:11value
03:12condition
03:13we
03:14can
03:15check
03:16either
03:17true
03:18or false
03:19so
03:20now
03:21replace
03:22if
03:23condition
03:24is
03:25true
03:26if
03:27condition
03:28is
03:29true
03:30if
03:31boot
03:32is
03:33true
03:34move
03:35left
03:36makes
03:37sense
03:38now
03:39move
03:40left
03:41basically
03:42direct
03:43if
03:44boot
03:45if
03:46true
03:47then
03:48block
03:49of code
03:50execute
03:51move
03:52left
03:53interesting
03:54if
03:55boot
03:56not
03:57boot
03:58not
03:59boot
04:00then
04:01else
04:02key
04:03word
04:04and
04:05interjewing
04:06if
04:07you
04:08automatic
04:09space
04:10is
04:11indentation
04:12indentation
04:13indentation
04:14python
04:15python
04:16read
04:17the
04:18basic
04:19concept
04:20which
04:21is
04:22indentation
04:23concept
04:24because
04:25when
04:26abc programming
04:27was
04:28built
04:29in
04:30the
04:31company
04:32then
04:33the
04:34problem
04:35was
04:36difficult
04:37to
04:38reading
04:39complex
04:40was
04:41complex
04:42then
04:43this
04:44programming
04:45is
04:46easy
04:47to
04:48see
04:49indentation
04:50concept
04:51that
04:52if
04:53you
04:54can
04:55see
04:56block
04:57of code
04:58code
04:59declare
05:00that
05:01is
05:02simple
05:03enter
05:04here
05:05else
05:06move
05:07right
05:09to
05:11d
05:12move
05:13left
05:14to
05:15d
05:16move
05:17right
05:18to
05:19c
05:20move
05:21left
05:22to
05:23d
05:24move
05:25left
05:26to
05:27c
05:28move
05:29right
05:30to
05:31c
05:32when
05:33this
05:34condition
05:35false
05:36this
05:37whole
05:38code
05:39this
05:40is
05:41block
05:42of code
05:43python
05:44indentation
05:45based
05:46block
05:47of code
05:48this
05:49run
05:50this
05:51run
05:52now
05:53we have
05:54two blocks
05:55of code
05:56and
05:57which
05:58base
05:59is
06:00true
06:01if
06:02it
06:03is
06:04run
06:05very
06:06simple
06:07it
06:08is
06:09no problem
06:10excellent
06:11condition
06:12always
06:13will be
06:14boolean
06:15will turn into
06:16boolean
06:17by one way
06:18or the other
06:19you will have
06:20numbers
06:21statement
06:22but
06:23it will boil down
06:24to a boolean
06:25value
06:26one
06:27example
06:28imagine
06:29we have
06:30cat
06:31and
06:32its value
06:33true
06:34and
06:35cat
06:36exists
06:37and
06:38its value
06:39true
06:40at the moment
06:41now
06:42we
06:44know
06:45that
06:46mouse
06:47is
06:48that
06:49cat
06:50not
06:51so
06:52print
06:53mouse
06:54eat
06:55cheese
06:56else
06:57print
06:58sorry
06:59print
07:00mouse
07:01run
07:02away
07:03right
07:05sorry
07:06print
07:07sorry
07:08print
07:13mouse
07:14run
07:15away
07:16right
07:18right
07:19now
07:20if
07:21cat
07:22is
07:23true
07:24then
07:25basically
07:26mouse
07:27should be
07:28true
07:29if
07:30cat
07:31is
07:32true
07:33if
07:34cat
07:35true
07:36is
07:37true
07:38cat
07:39in the room
07:40is
07:41true
07:42then
07:43mouse
07:44run
07:45away
07:46else
07:47doesn't
07:48eat
07:49cheese
07:50cat
07:51exists
07:52run
07:53if
07:54here
07:55replace
07:56basically
07:57cat
07:58is
07:59true
08:00if
08:01true
08:02then
08:03mouse
08:04run
08:05away
08:06however
08:07cat
08:08is
08:09false
08:10cat
08:11in the room
08:12is
08:13false
08:14cat
08:15not
08:16mouse
08:17cheese
08:18eat
08:19cheese
08:20okay
08:21now
08:22my
08:23question
08:24is
08:25cat
08:26not
08:27what if
08:28house owner
08:29is there
08:30is
08:31a
08:32of
08:33books
08:36is
08:37a
08:38third
08:39condition
08:40is
08:41either
08:42c
08:43or
08:44d
08:45is
08:46not
08:47cat کے علاوہ چلو cat نہیں ہے
08:49تو house owner تو ہے نا
08:50گھر میں بیٹھا ہوا
08:50تو جب house owner ہوتا ہے
08:52تب تو mouse cheese نہیں کھاتا
08:53یا کھاتا ہے
08:54نہیں کھاتا
08:55اوکے
08:57تو میں اس طرح کرتا ہوں
08:58میں ایک اور condition ڈال رہنا دوں
09:01owner
09:01اور owner true ہے جی
09:04اب تو
09:06mouse کو cheese نہیں کھانی چاہیے
09:09اب بھی mouse کو run ہونا چاہیے
09:11run away ہونا چاہیے
09:12یا پھر at least derive away ہونا چاہیے
09:14تو third condition
09:16کوئی اور جو کہ cat کے علاوہ ہے
09:19اگر ڈال نہیں ہو
09:19تو اس کے لیے ایک اور keyword use ہوتا ہے
09:21اس کو کہتے ہیں alif
09:22alif
09:23اور alif کے ساتھ
09:25again جس طرح if کے ساتھ condition لکھتے ہیں
09:27ہم
09:27alif کے ساتھ condition لکھتے ہیں
09:30تو میں کہتا ہوں
09:31if owner
09:31اگر owner ہے
09:33تو پھر
09:34پھر کیا ہوگا
09:36mouse is scared
09:38mouse ڈرہا ہوا ہے
09:41بلی سے تو
09:42ڈر کے دھوڑ جاتا نا
09:44چلیں
09:44اب میں owner true ہے
09:45میں اس کو run کرتا ہوں
09:46mouse is scared
09:48however
09:49جب دونوں نہیں ہیں
09:50false
09:51ٹھیک ہے
09:53اب میں اس کو run کرتا ہوں
09:54تو mouse eat cheese
09:56جب دونوں false ہیں
09:57اب اگر اس میں cat true
09:59گبلی آ جاتی ہے
10:01تو of course
10:02mouse run away ہو جاتا ہے
10:03لیکن
10:04اگر اس میں
10:05cat نہیں ہوتی
10:07اور ہمارے پاس
10:09let's say
10:10owner ہوتا ہے
10:11تو پھر
10:12mouse
10:12در جاتا ہے
10:14تو آپ ذرا
10:14غور کریں
10:15کہ اگر میں
10:15اس کو ایک ایک
10:16block میں
10:17convert کر دوں
10:17تو if
10:18alif
10:19اور else
10:20یہ تین
10:21sorry
10:22if
10:22اور alif
10:23دو
10:24different conditions
10:24کو represent
10:25کر رہے ہیں
10:26depending upon
10:27which condition
10:28is true
10:29وہ block of code
10:30execute ہو جائے گا
10:31اب میرا question یہ ہے
10:32what if both are true
10:33آپ کے خیال سے
10:34کونسا execute ہوگا
10:35تو چلیے دیکھتے ہیں
10:36میں اس کو جو ہی run کرتا ہوں
10:37تو mouse run away
10:38اس کی reason یہ ہے
10:39کہ جو پہلا block encounter ہوا
10:43وہ code execute ہوا
10:44جو پہلا block true
10:46کے ساتھ encounter ہوا
10:47وہ code execute ہوا
10:48باقی ساری چیزیں
10:50skip ہو گئیں
10:50باقی ساری چیزوں کو
10:52اگنی کیا گیا
10:52اگنی کیا گیا
10:53line 9 to 11
10:55run نہیں ہوا
10:56make sense
10:57very easy right
10:58okay

Recommended