eLearning

We are a professional site that will give you the strongest methods to get learn and we will teach you everything about programming and technology

PYTHON

Breaking News

PYTHON
PYTHON
جاري التحميل ...

Conditions in Python Lesson 4

Conditions in Python Lesson 4:



In the English language the word conditions: means. And we use the terms in programming languages ​​to determine the way to work on the program and the conditions are considered one of the most important tools for programming languages ​​in general, so imagine that there is a programming language without the conditions, how will you create an integrated program, and from its name, it executes an order if a specific event has occurred or did not happen.

Of course, there are several ways to set the condition or different conditions, and we will now, as we are accustomed to explaining the conditions in Python, in the initial form, and then include in future lessons to study almost all cases and methods of implementing and writing conditions

We will now explain the condition statements in Python

The following structure explains the Syntax method:

- (condition) if condition

In this line, we have set a condition so that if this condition is true then implement the code

- (condition) elif condition

Also in this line, we have set a condition so that if this condition is true then implement the code

- (condition) else

In this line, we have set a condition so that if any of the previously set conditions are not met, then implement this code instead


Note that it is not necessary to put the three previous sentences and put them in the previous example completely inside each program, but only to use the condition is required to use the condition statement (if)


Example:

Var = happy

Var = sad

If (happy == True):

      Print ("smile")

Elif (sad == True):

      Print ("be happy")

 Else:

        Print ("I dunno what I say")


Note: The Tab must be indented so that the program knows that the instructions are related to the conditional statement.

Explanation of condition statements in the Python programming language

Word (sentence) condition (if)

This word in itself is translated into Arabic (if), and it is used in the event that you want to implement a code (command) according to a specific condition that you put in place just like normal life behavior.

Word (sentence) condition (else)

This word in itself is translated into Arabic (something else).

And it is used only if you want to execute a specific code (command) in case all the conditions before it was not met, or in other words (false).

Taking into account that it must always be placed in the last conditional sentences within the program structure, as it is resorted to only in the event that no conditional sentence written before it is executed.

(Elif) (else if) (elif)

عن الكاتب

ADMIN

التعليقات


اتصل بنا

If you like the content of our blog, we hope to stay in constant contact, just enter your email to subscribe to the blog express mail so that you will receive the new blog first-hand, and you can send a message by clicking the next button ...

جميع الحقوق محفوظة

eLearning