#19 Python Tutorial for Beginners | If Elif Else Statement in Python

#19 Python Tutorial for Beginners | If Elif Else Statement in Python

Introduction to CPU and Logical Unit

In this video, Ivan introduces the concept of CPU and its three parts: CU, MU, and ALU. He then focuses on the memory unit (MU) and arithmetic unit (AU) of ALU that perform calculations. Later he explains the logical unit of ALU that makes a computer think by applying different conditions.

Understanding Logical Unit

  • The logical unit is responsible for making a computer think by applying different conditions.
  • As programmers, we write statements to specify the flow of execution based on certain conditions using the special keyword "if".
  • We can use "if" to execute one set of statements if a condition is true or another set if it's false.
  • The syntax for "if" statement in Python is if <condition>:, where <condition> can be either true or false.

Working with If Statement

  • To execute a block of code under an "if" statement, we need to follow proper indentation rules in Python.
  • All statements that belong to an "if" statement should have the same level of indentation. Otherwise, they will not be executed as part of that block.

Overall, this video provides an introduction to CPU and its components while focusing on the logical unit's role in making computers think by applying different conditions. It also explains how we can use "if" statements in Python to specify the flow of execution based on certain conditions while following proper indentation rules.

I apologize, but I cannot see any transcript provided in the previous messages. Please provide me with the transcript so that I can create a comprehensive and informative markdown file.

Python If Else Statements

In this section, the speaker explains how to use if-else statements in Python. The speaker demonstrates how to improve performance by using else instead of another if statement. They also explain nested if statements and how to use if/elif/else statements.

Using Else Instead of Another If Statement

  • To improve performance, use else instead of another if statement when checking for even numbers.
  • Use debug and F8 or the flow to see that R is 0 after skipping the else block.

Nested If Statements

  • Nested if statements are used when there are conditions that are different from each other.
  • Indentation is used to show which print statement belongs to which if statement.
  • An entire tree of ifs can be created with nested ifs.

If/Elif/Else Statements

  • Use round brackets instead of open brackets for conditions (optional).
  • If/elif/else statements can be used when there are multiple conditions with different outputs.
  • Each condition is checked in order until one is true, then its corresponding output is printed.

Python For Loops

In this section, the speaker explains how to use for loops in Python. They demonstrate how to loop through a range of numbers and through a string.

Looping Through a Range of Numbers

  • Use for i in range() to loop through a range of numbers.
  • The loop will start at the first number specified and end at one less than the second number specified.
  • Use print(i) inside the loop to print each number as it loops through.

Looping Through a String

  • Use for letter in word to loop through each letter in a string.
  • Use print(letter) inside the loop to print each letter as it loops through.

If, Elif and Else Statements

In this section, the speaker explains how to use if, elif and else statements in Python.

Using Elif Statement

  • Elif statement is used when the first condition is false.
  • Debugging can be done by putting a breakpoint in the code.
  • If the first condition is false, it will jump to Elif statement.
  • If none of the conditions match, we can print "wrong input" using else statement.

Conclusion

  • Using if, elif and else statements can help us execute different blocks of code based on different conditions.
  • The assignment for practicing these concepts will be available at the end of the video.
Video description

Check out our courses: AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS Coupon: TELUSKO10 (10% Discount) Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4 Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 TELUSKO Android App : https://bit.ly/TeluskoApp In this lecture we will learn: - Different units of a CPU - Conditional statements in Python - If and Else statements - Execution of conditional blocks - What is Indentation in Python? - Nested if and else statements - if, elif and else statements #1 - CPU has three parts: CU (Control Unit), ALU ( Arithmetic Logic Unit) and MU ( Memory unit). - MU is used to store variables and data. - ALU has two parts: 1. AU - Arithmetic Unit ( it performs mathematical calculations) 2. LU - Logical Unit ( it makes a computer think something) #2 If statement:- - In programming, we have to apply conditions as per the logic of the code. In python, conditions can be applied through the if keyword. - Use of the if keyword specifies the flow of execution of the code. - Based on the condition of the problem statement, if keyword helps to decide which set of statements should be executed. Syntax:- if (condition): statement; - The statements of the if block will be executed only when the condition of the if statement is true. If the condition is false then it will skip the execution of statements present inside the if block. - If consists of a block where you can write multiple statements. In python, it is also known as Suite. #2 Indentation:- - In Python, we have to follow certain indentations that specify the conditions that are present inside a certain block. - Indentation simply means a certain number of spaces at the beginning of a code line. - Indentation increases the readability of the code. #3 Else block:- - We can also use multiple if blocks in a code. - Multiple uses of the if block decrease the efficiency of a code as the condition will be checked again and again in each if block. - To make the code efficient, we use the else block. - If the condition of the if block is true then the else block will be skipped. And if the condition of the if block is false then the else block will be checked and executed. #4 Nested if and else statements:- - Nested if and else statements are also allowed in Python. - if statement can also be checked inside other if statement. This conditional statement is called a nested if statement. - In nested, the inner if condition will be checked only if the outer if condition is true and that helps to see multiple conditions to be satisfied. - Round brackets for putting a condition in the if statement is optional. #5 if, elif and else statements:- - elif stands for if-else. - The if-elif statement is a shortcut of if..else chain. - If the if condition s false, then the condition inside the elif will be checked and executed. - While using if-elif statement at the end else block is added that will be executed when none of the above if-elif statements is true. Github :- https://github.com/navinreddy20/Python- Python for Beginners :- http://bit.ly/3JOLQhl Editing Monitors : https://amzn.to/2RfKWgL https://amzn.to/2Q665JW https://amzn.to/2OUP21a. Java:- https://bit.ly/JavaUdemyTelusko Spring:- https://bit.ly/SpringUdemyTelusko More Learning : Java :- https://bit.ly/3x6rr0N Python :- https://bit.ly/3GRc7JX Django :- https://bit.ly/3MmoJK6 JavaScript :- https://bit.ly/3tiAlHo Node JS :- https://bit.ly/3GT4liq Rest Api :-https://bit.ly/3MjhZwt Servlet :- https://bit.ly/3Q7eA7k Spring Framework :- https://bit.ly/3xi7buh Design Patterns in Java :- https://bit.ly/3MocXiq Docker :- https://bit.ly/3xjWzLA Blockchain Tutorial :- https://bit.ly/3NSbOkc Corda Tutorial:- https://bit.ly/3thbUKa Hyperledger Fabric :- https://bit.ly/38RZCRB NoSQL Tutorial :- https://bit.ly/3aJpRuc Mysql Tutorial :- https://bit.ly/3thpr4L Data Structures using Java :- https://bit.ly/3MuJa7S Git Tutorial :- https://bit.ly/3NXyCPu Donation: PayPal Id : navinreddy20 https://www.telusko.com

#19 Python Tutorial for Beginners | If Elif Else Statement in Python | YouTube Video Summary | Video Highlight