Start To Learn Python Right Now EP08: Work with Python Gates & Modifiers




In the previous tutorial, we learn how to use strings and various options we can use with Python Stings. Now I'm going to explain basic but important functionality in every Programming Language. It is Gates.  Let's learn what is a Gate and how to use them.  

What is A Gate...

   Gate is a king of boolean operation which means giving a true or false value as the output of gate in a specific task. Consider that you have three values called x, y, and z. Now you need to return true if the x and y in z. So in that case you can use AND gate.  These are the other GATES that you can use for your projects.   

NOTE: Don't use numbers with the gates, because Python integers I mean numbers are not iterable. so you can't loop through them. If you want to learn about it, you can refer the EPISODE 04

   

These are some Python Gates...

  •        AND - AND gate is used to return a value if all your values are true. Like you have a ball, and your friend also has a ball. If both values are in one bucket return true. Let's see a practical example now        
                                    a = "www.softexs.com"
                                    b = "www"
                                    c = ".com"
                                    if b and c in a:
                                  print("Success")

  • OR - OR gate is used to return true if one of your value is true. It means you have two values and a main values set, and you need to return true if one of your values is in your main values set. This is the practical example
                            a = "www.softexs.com"
                            b = "www"
                            c = ".com"
                            if b or c in a:
                                   print("Success")


    
                                    
  • NOT - not is used to execute the opposite operation for the above Gates we talked about. You already know that we used syntax with all the gates. We are putting NOT modifier in front of it to make an opposite operation. It will be clear to you with the below examples. 
                          a = "www.softexs.com"
                          d = "hello"
                          e = "Python"
                          if d and e not in a:
                                  print("FALSE")
                    In here I put gate and modifier to execute the next task if d and e both are not in string a. so, "hello" or "Python" is not in the string a, then it eecutes the next task print()

                        a = "www.softexs.com"
                        b = "www"
                        d = "hello"
                        if b or d not in a:
                              print("FALSE")
                   In here I put OR and NOT to perform on the next task if one of the value b or d is not in a. Value b is "www" and it is on h string a, but d is "hello" and it is not in string a. Now we already know OR gates execute the task if one value is true. With the NOT, we make the opposite of it. If one of the wrong value is true, perform the next task. 

  • IS - IS is used is work like equal. It means "IS" only returns true if the values you entered are the same. Else is will return FALSE. this is how it works.
                   a = "www.softexs.com"
                   if a is "www.softexs.com":
                         print("Yes")

This is all I need to talk about in this tutorial. You can experiment more with things you learned. Also, you can put your questions in the comments section or community section. Let's talk more about Python in the next tutorial.

Post a Comment

If you have any doubt, Let us know

Previous Post Next Post