Python‎ > ‎Control Flow‎ > ‎

if

http://www.adilwaseem.com/

Definition
Python executes a argument if condition is fulfilled, otherwise execute else if and else argument.

Syntax
if "argument" ":"
    "do this"
elif "argument" ":"
    "do this" 
else:
    "do this"

Parameters
Wide range of parameters are permissible.

Examples
if statement..... subject to while loop
While loop return with the value from 14 to 1.
 x = 15
while x > 0:              
   x = x -1
   if x == 10:
      continue
   print("x value is equal :", x)

>>> 
x value is equal : 14
x value is equal : 13
x value is equal : 12
x value is equal : 11
x value is equal : 9
x value is equal : 8
x value is equal : 7
x value is equal : 6
x value is equal : 5
x value is equal : 4
x value is equal : 3
x value is equal : 2
x value is equal : 1
x value is equal : 0
>>> 


class...: def....: if statement
The class method executed the if statement.
import operator
class add_value:
    def __init__(self, a):
        self.a=a
        if self.a==float(a):
            print("The value:",self.a, ",is float:")
        else:
            print("Value accepted: ", self.a)
                  
                
value=3.134

add_value(value)

>>> 
The value: 3.134 ,is float:
>>>


class....: def...: if....:
The class method return the complex values and tested the equality of the values.
 class complex_value:
    def __init__(self, a,b,c):

        self.a=complex(a).conjugate()
        self.b=complex(b).imag
        self.c=complex(c).real

        print("The comlex conjugate value of a is: ",self.a)
        print("The complex imag value of b is: ",self.b)
        print("The complex  real value of c is: ",self.c)
        
        if self.a.__eq__(complex(a).conjugate()):
            print("The value of a is equal to complex(a) conjugate")
        else:
             print("The value of a is NOT equal to complex(a) conjugate")
            

        if self.b.__eq__(complex(b).imag):
            print("The value of b is equal to complex(b) imag")
        else:
            print("The value of b is NOT equal to complex(b) imag")


        if self.c.__eq__(complex(c).real):
            print("The value of c is equal to complex(c) imag")
        else:
            print("The value of c is NOT equal to complex(c) imag")

           
value1=81
value2=222
value3=33
complex_value(value1,value2, value3)

>>> 
The comlex conjugate value of a is: (81-0j)
The complex imag value of b is: 0.0
The complex real value of c is: 33.0
The value of a is equal to complex(a) conjugate
The value of b is equal to complex(b) imag
The value of c is equal to complex(c) imag
>>>


Here is how Error method printed the error message.
 import webbrowser

x=input("Please enter web dress:")

if x.__eq__('www.pythonlake.com'):
    webbrowser.open(x)

    webbrowser.Error("Not allowed to access the file")

>>> 
Please enter web dress:www.amazon.com
Not allowed to access the file
>>> 


if....:webbrowser.open_new()
webbrowser.open_new()
import webbrowser

x=input("Please enter your web address: ")
y=str(x)

if y.startswith("y"):
    print("Access denied")
    webbrowser.open_new(y)

>>> 
Please enter your web address: yellow.com
Access denied



Here, in this example, the IntegerField validated number entered should be in record and before the Field vale is passed on HttpResponseRedirect in views.py and index.html files.
Steps for creating virtual environment, startproject, startapps, & running server:
  • virtualenv myvirtualenv
  • cd  mysite
  • .\Scripts\activate
  • pip install django
  • python .\Scripts\django-admin.py startproject mysite
  • cd mysite
  • python manage.py startapp myapphttp
  • python manage.py runserver 



setting.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles','myapphttp',
)

urls.py

from django.conf.urls import include, url

from myapphttp.views import response

urlpatterns = [
      url(r'^', response),
]

myapphttp/forms.py

from django import forms



def Validate(value):
    pin=[1101,2945,3635,5550,3334,5553,2822,4624,3221,6453,2223,4456,5462]
    if value not in pin:
        raise ValidationError('%s : The pin number is not in our record.'% value)

class IntegerField(forms.Form):
    number=forms.IntegerField(label='Number' ,validators=[Validate])

myapphttp/views.py

from django.shortcuts import render

from .forms import IntegerField

def response(request):
    if request.method == 'POST':
        form=IntegerField(request.POST)
        if form.is_valid():
            return HttpResponseRedirect('/Thanks-for-submitting-your-request/')
    else:
        form = IntegerField()

    return render(request, 'myapphttp\index.html', {'form':form})


myapphttp/index.html

<!DOCTYPE html>
<html>
<title> </title>
<body>

<form action="/pin-not-found/" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit" />
</form>

</body>
</html>






Here, in this examples, the form validation is processed through the calling the function in the forms.EmailField(). The  function validated the list items after the form is submitted through POST method.
 Steps for creating virtual environment, startproject, startapps, & running server:
  • virtualenv myenv
  • cd  myenv
  • .\Scripts\activate
  • .\Scripts\deactivate
  • pip install django
  • python .\Scripts\django-admin.py startproject mysite
  • cd mysite
  • python manage.py startapp myapp
  • python manage.py runserver

Files


setting.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles', 'myapp', 
)

urls.py

from myapp.views import submit

urlpatterns = [
    url(r'^', submit),
]

myapp/forms.py

from django import forms
from django.core.exceptions import ValidationError

def Validate(email):
    list=['adil@adilwaseem.com', 'adil@pythonlake.com','contact@adilwaseem.com']
    if email not in list:
        raise ValidationError("%s is not in our record."% email )

class AccessForm(forms.Form):
    email=forms.EmailField(label='Email',validators=[Validate])

myapp/views.py

from django.shortcuts import render

from .forms import AccessForm

def submit(request):
    if request.method == 'POST':
        form=AccessForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect('/thanks/')
    else:
        form = AccessForm()

    return render(request, 'myapp\index.html', {'form':form})

myapp/index.html

<!DOCTYPE html>
<html>
<title> </title>
<body>

<form action="/Response/" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit" />
</form>

</body>
</html>

view at localhost:8000/







 The Response returns the union of frozenset x, y. 
from pyramid.response import Response

def frozenset1(request):
    x=frozenset({7,9,11,13})
    y=frozenset({5,10,15})
    z=frozenset.union(x,y)
    z=str(z)
    return Response('The union of frozenset is:' + z)
        
if __name__ == '__main__':
    config = Configurator()
    config.add_route('set', '/')
    config.add_view(frozenset1, route_name='set')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 1050, app)
    server.serve_forever()






Equality test run through the pyramid web framework.
 
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def test(request):
    x=pow(3,10)
    y=13
    if x.__gt__(y):
        return Response('x is greater than y.')
    else:
        return Response('x is not greater than y.')

def main():
    config = Configurator()
    config.add_route('index', '/')                        
    config.add_view(test, route_name='index')
    app = config.make_wsgi_app()
    return app

if __name__ == '__main__':
    app = main()
    server = make_server('0.0.0.0', 1000, app)
    print ('Starting up server on http://localhost:1000')
    server.serve_forever()






The pyramid returns with the if statement execution after testing equation of the values of two variable. 
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def test(request):
    x=range(1,0)
    y=13
    if y in x:
        return Response('y is in x')
    else:
        return Response('y is not in x')

def main():
    config = Configurator()
    config.add_route('index', '/')                        
    config.add_view(test, route_name='index')
    app = config.make_wsgi_app()
    return app

if __name__ == '__main__':
    app = main()
    server = make_server('0.0.0.0', 1000, app)
    print ('Starting up server on http://localhost:1000')
    server.serve_forever()






The headers returns with the server response to get request and if statement is used to open the webbrowser condition to dict.keys.
 >>>import requests
>>> re=requests.get('http://www.pythonlake.com', params='Pythonlake')
>>> re.headers
{'x-content-type-options': 'nosniff', 'server': 'GSE', 'x-robots-tag': 'noarchive', 'x-xss-protection': '1; mode=block', 'date': 'Mon, 27 Apr 2015 13:27:21 GMT', 'accept-ranges': 'none', 'vary': 'Accept-Encoding', 'cache-control': 'public, max-age=5', 'transfer-encoding': 'chunked', 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Mon, 27 Apr 2015 13:16:45 GMT', 'expires': 'Mon, 27 Apr 2015 13:27:26 GMT', 'alternate-protocol': '80:quic,p=1,80:quic,p=1'}
>>> 
>>> h.keys
<bound method CaseInsensitiveDict.keys of {'x-content-type-options': 'nosniff', 'server': 'GSE', 'x-robots-tag': 'noarchive', 'x-xss-protection': '1; mode=block', 'date': 'Mon, 27 Apr 2015 13:27:21 GMT', 'accept-ranges': 'none', 'vary': 'Accept-Encoding', 'cache-control': 'public, max-age=5', 'transfer-encoding': 'chunked', 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Mon, 27 Apr 2015 13:16:45 GMT', 'expires': 'Mon, 27 Apr 2015 13:27:26 GMT', 'alternate-protocol': '80:quic,p=1,80:quic,p=1'}>
>>> if 'server' in h.keys():
...     >>> webbrowser.open_new('www.pythonlake.com')
True
>>>



The turtle dot loop is generated through while statement and colors are selected through the random.sample method.
import turtle
import random

turtle.speed(100)
h=50
w=50
s.screensize(h,w)
y=r

while y > 0:
    ps=random.randrange(1,10)
    turtle.pensize(ps)

    turtle.pendown()
    y=y-1
    color_list= ['snow', 'ghostwhite', 'whitesmoke', 'gainsboro', 'floralwhite', 'oldlace',
    'linen', 'antiquewhite', 'papayawhip', 'blanchedalmond', 'bisque', 'peachpuff',
    'navajowhite', 'lemonchiffon', 'mintcream', 'azure', 'aliceblue', 'lavender',
    'lavenderblush', 'mistyrose', 'darkslategray', 'dimgray', 'slategray',
    'lightslategray', 'gray', 'lightgrey', 'midnightblue', 'navy', 'cornflowerblue', 'darkslateblue',
    'slateblue', 'mediumslateblue', 'lightslateblue', 'mediumblue', 'royalblue',  'blue',
    'dodgerblue', 'deepskyblue', 'skyblue', 'lightskyblue', 'steelblue', 'lightsteelblue',
    'lightblue', 'powderblue', 'paleturquoise', 'darkturquoise', 'mediumturquoise', 'turquoise',
    'cyan', 'lightcyan', 'cadetblue', 'mediumaquamarine', 'aquamarine', 'darkgreen', 'darkolivegreen',
    'darkseagreen', 'seagreen', 'mediumseagreen', 'lightseagreen', 'palegreen', 'springgreen',
    'lawngreen', 'mediumspringgreen', 'greenyellow', 'limegreen', 'yellowgreen',
    'forestgreen', 'olivedrab', 'darkkhaki', 'khaki', 'palegoldenrod', 'lightgoldenrodyellow',
    'lightyellow', 'yellow', 'gold', 'lightgoldenrod', 'goldenrod', 'darkgoldenrod', 'rosybrown',
    'indianred', 'saddlebrown', 'sandybrown',
    'darksalmon', 'salmon', 'lightsalmon', 'orange', 'darkorange',
    'coral', 'lightcoral', 'tomato', 'orangered', 'red', 'hotpink', 'deeppink', 'pink', 'lightpink',
    'palevioletred', 'maroon', 'mediumvioletred', 'violetred',
    'mediumorchid', 'darkorchid', 'darkviolet', 'blueviolet', 'purple', 'mediumpurple',
    'thistle', 'snow2', 'snow3',
    'snow4', 'seashell2', 'seashell3', 'seashell4', 'AntiqueWhite1', 'AntiqueWhite2',
    'AntiqueWhite3', 'AntiqueWhite4', 'bisque2', 'bisque3', 'bisque4', 'PeachPuff2',
    'PeachPuff3', 'PeachPuff4', 'NavajoWhite2', 'NavajoWhite3', 'NavajoWhite4',
    'LemonChiffon2', 'LemonChiffon3', 'LemonChiffon4', 'cornsilk2', 'cornsilk3',
    'cornsilk4', 'ivory2', 'ivory3', 'ivory4', 'honeydew2', 'honeydew3', 'honeydew4',
    'LavenderBlush2', 'LavenderBlush3', 'LavenderBlush4', 'MistyRose2', 'MistyRose3',
    'MistyRose4', 'azure2', 'azure3', 'azure4', 'SlateBlue1', 'SlateBlue2', 'SlateBlue3',
    'SlateBlue4', 'RoyalBlue1', 'RoyalBlue2', 'RoyalBlue3', 'RoyalBlue4', 'blue2', 'blue4',
    'DodgerBlue2', 'DodgerBlue3', 'DodgerBlue4', 'SteelBlue1', 'SteelBlue2',
    'SteelBlue3', 'SteelBlue4', 'DeepSkyBlue2', 'DeepSkyBlue3', 'DeepSkyBlue4',
    'SkyBlue1', 'SkyBlue2', 'SkyBlue3', 'SkyBlue4', 'LightSkyBlue1', 'LightSkyBlue2',
    'LightSkyBlue3', 'LightSkyBlue4', 'SlateGray1', 'SlateGray2', 'SlateGray3',
    'SlateGray4', 'LightSteelBlue1', 'LightSteelBlue2', 'LightSteelBlue3',
    'LightSteelBlue4', 'LightBlue1', 'LightBlue2', 'LightBlue3', 'LightBlue4',
    'LightCyan2', 'LightCyan3', 'LightCyan4', 'PaleTurquoise1', 'PaleTurquoise2',
    'PaleTurquoise3', 'PaleTurquoise4', 'CadetBlue1', 'CadetBlue2', 'CadetBlue3',
    'CadetBlue4', 'turquoise1', 'turquoise2', 'turquoise3', 'turquoise4', 'cyan2', 'cyan3',
    'cyan4', 'DarkSlateGray1', 'DarkSlateGray2', 'DarkSlateGray3', 'DarkSlateGray4',
    'aquamarine2', 'aquamarine4', 'DarkSeaGreen1', 'DarkSeaGreen2', 'DarkSeaGreen3',
    'DarkSeaGreen4', 'SeaGreen1', 'SeaGreen2', 'SeaGreen3', 'PaleGreen1', 'PaleGreen2',
    'PaleGreen3', 'PaleGreen4', 'SpringGreen2', 'SpringGreen3', 'SpringGreen4',
    'green2', 'green3', 'green4', 'chartreuse2', 'chartreuse3', 'chartreuse4',
    'OliveDrab1', 'OliveDrab2', 'OliveDrab4', 'DarkOliveGreen1', 'DarkOliveGreen2',
    'DarkOliveGreen3', 'DarkOliveGreen4', 'khaki1', 'khaki2', 'khaki3', 'khaki4',
    'LightGoldenrod1', 'LightGoldenrod2', 'LightGoldenrod3', 'LightGoldenrod4',
    'LightYellow2', 'LightYellow3', 'LightYellow4', 'yellow2', 'yellow3', 'yellow4',
    'gold2', 'gold3', 'gold4', 'goldenrod1', 'goldenrod2', 'goldenrod3', 'goldenrod4',
    'DarkGoldenrod1', 'DarkGoldenrod2', 'DarkGoldenrod3', 'DarkGoldenrod4',
    'RosyBrown1', 'RosyBrown2', 'RosyBrown3', 'RosyBrown4', 'IndianRed1', 'IndianRed2',
    'IndianRed3', 'IndianRed4', 'sienna1', 'sienna2', 'sienna3', 'sienna4', 'burlywood1',
    'burlywood2', 'burlywood3', 'burlywood4', 'wheat1', 'wheat2', 'wheat3', 'wheat4', 'tan1',
    'tan2', 'tan4', 'chocolate1', 'chocolate2', 'chocolate3', 'firebrick1', 'firebrick2',
    'firebrick3', 'firebrick4', 'brown1', 'brown2', 'brown3', 'brown4', 'salmon1', 'salmon2',
    'salmon3', 'salmon4', 'LightSalmon2', 'LightSalmon3', 'LightSalmon4', 'orange2',
    'orange3', 'orange4', 'DarkOrange1', 'DarkOrange2', 'DarkOrange3', 'DarkOrange4',
    'coral1', 'coral2', 'coral3', 'coral4', 'tomato2', 'tomato3', 'tomato4', 'OrangeRed2',
    'OrangeRed3', 'OrangeRed4', 'red2', 'red3', 'red4', 'DeepPink2', 'DeepPink3', 'DeepPink4',
    'HotPink1', 'HotPink2', 'HotPink3', 'HotPink4', 'pink1', 'pink2', 'pink3', 'pink4',
    'LightPink1', 'LightPink2', 'LightPink3', 'LightPink4', 'PaleVioletRed1',
    'PaleVioletRed2', 'PaleVioletRed3', 'PaleVioletRed4', 'maroon1', 'maroon2',
    'maroon3', 'maroon4', 'VioletRed1', 'VioletRed2', 'VioletRed3', 'VioletRed4',
    'magenta2', 'magenta3', 'magenta4', 'orchid1', 'orchid2', 'orchid3', 'orchid4', 'plum1',
    'plum2', 'plum3', 'plum4', 'MediumOrchid1', 'MediumOrchid2', 'MediumOrchid3',
    'MediumOrchid4', 'DarkOrchid1', 'DarkOrchid2', 'DarkOrchid3', 'DarkOrchid4',
    'purple1', 'purple2', 'purple3', 'purple4', 'MediumPurple1', 'MediumPurple2',
    'MediumPurple3', 'MediumPurple4', 'thistle1', 'thistle2', 'thistle3', 'thistle4',
    'gray1', 'gray2', 'gray3', 'gray4', 'gray5', 'gray6', 'gray7', 'gray8', 'gray9', 'gray10',
    'gray11', 'gray12', 'gray13', 'gray14', 'gray15', 'gray16', 'gray17', 'gray18', 'gray19',
    'gray20', 'gray21', 'gray22', 'gray23', 'gray24', 'gray25', 'gray26', 'gray27', 'gray28',
    'gray29', 'gray30', 'gray31', 'gray32', 'gray33', 'gray34', 'gray35', 'gray36', 'gray37',
    'gray38', 'gray39', 'gray40', 'gray42', 'gray43', 'gray44', 'gray45', 'gray46', 'gray47',
    'gray48', 'gray49', 'gray50', 'gray51', 'gray52', 'gray53', 'gray54', 'gray55', 'gray56',
    'gray57', 'gray58', 'gray59', 'gray60', 'gray61', 'gray62', 'gray63', 'gray64', 'gray65',
    'gray66', 'gray67', 'gray68', 'gray69', 'gray70', 'gray71', 'gray72', 'gray73', 'gray74',
    'gray75', 'gray76', 'gray77', 'gray78', 'gray79', 'gray80', 'gray81', 'gray82', 'gray83',
    'gray84', 'gray85', 'gray86', 'gray87', 'gray88', 'gray89', 'gray90', 'gray91', 'gray92',
    'gray93', 'gray94', 'gray95', 'gray97', 'gray98', 'gray99']

    colors=random.sample(color_list,1)
    turtle.color(colors)
    turtle.bgcolor("black")
    turtle.dot(y)

    if y==0:
     
        px=random.randrange(-300,300)
        py=random.randrange(-300,300)
        turtle.penup()
        turtle.setpos(px,py)
        y=random.randrange(0,150)




                
If statement is used on the method of requests.request() to get the open link in the webbrowser.
 >>> import requests
>>> re=requests.request('Get','http://www.pythonlake.com')
>>> re
<Response [200]>
>>> if re.ok==True:
...     webbrowser.open_new('www.adilwaseem.com')
...     
True
>>> 


If statement is used to authenticate the user.
 x = input("Enter your name: ")
if x=="Adil":
    print("Welcome, Adil")
elif x == "John":
    print("No, you're not Adil")
else:
    print("You're not allowed to use this system")
   
>>>
Enter your name: john
You're not allowed to use this system
>>>

class.....: def __init__()......if...: if 
The function tested whether the string value is single word, or contain non-string values through input().
 class str_methods():
    def __init__(self, a,b,c):

        identifier=str.isidentifier(a)

        if str.isidentifier(a).__eq__(True):
            print("Full name should not contain special characters or numbers")
            
        else:
            print("Your full not name accepted")

        
      
        alpha=str.isalpha(b)
        
        if alpha.__ne__(False):
            print("Full name accepted")

            lower=str.lower(c)
            if lower.__eq__(str.lower(c)):
                 str.upper(c)
                 print("System convert your name to uppercase:", str.upper(c))
            else:
                 print("Your name accepted")

        else:
            print("Full name can't be one word")

                    

input_text=input("Please enter  your full name: ")

str_methods(input_text, input_text,input_text)
    
          

>>> 
Please enter your full name: Adil22
Full name should not contain special characters or numbers
Full name can't be one word
>>>        



if statement subject to input() number  
Here in this sample code the variable assigned the numeric ranges and and if statement is tested on these variables.
a=range(1,18)
b=range(18,40)
c=range(40,99)
print("Please enter your age")
d=input()
if d is a:
    print("You're authorized to work")
elif d is b:
    print ("You are authorized to work")
else:
    print("You can request accommodation")

>>>
Please enter your age

28
You can request accommodation
>>>

If statement is deployed to get the letters in lower and uppercase.
import string
search1=str(input("Type your search: "))
if search1=="alpalphabets" or "English letter" or "letters":
        print(string.ascii_letters)
>>>
Type your search: alphabets
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM
NOPQRSTUVWXYZ
>>>
 
if str.isalnum()
The method tested the variable through if statement whether it is number or not through str.isalnum().
 x="12233"
if x.isalnum():
        print("yes, you're right")
>>> 
yes, you're right
>>>

The class executed the loop inheriting the values from the class url.
 
class url():
    x=10
    y=15

class loop(url):
    y=3
    if y==3:
        for in range(0,url.x):
            print(i)
            if i==9:
                print("Start of h loop")
            
        for h in range(0,url.y):
            print(h)

>>> 
0
1
2
3
4
5
6
7
8
9
Start of h loop
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> 



if variable==number
for loop subject to break where x is equal 8.
 for x in range(1,10):
    print(x)
    if x==8:
        break
    else:
        print(x)

>>> 
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
>>> 


if str.endswith()
The str.endswith() is used in if statement.
 x="122cc"
if x.endswith("c"):
print("yes, you're right")
else:
print("It is not numeric")
>>> 
yes, you're right
>>> 

if isalpha()
The method str.isalpha() is tested through if statement.
 Name=str(input("Please enter your name: "))
if str.isalpha(Name):
print("Name can be single character.")
else:
print("Okay")
>>> 
Please enter your name: p
Name can be single character
>>>

if statement (string is decimal)
if statement test whether string object is decimal or not
 x="122cc"
if x.isdecimal():
    print("yes, you're right")
else:
    print("It is not Decimal")

>>> 
it is not Decimal
>>>


if statement sum(map(lamda))__lt__(value()
If statement returns that the sum of the x/y is not less than 2.
 import math
x={math.factorial(81),math.sqrt(49),math.pow(4,2),math.e,math.exp(44)}
y={math.floor(3.12),math.fmod(3,2),math.fabs(22), math.ceil(1)}
if sum(map(lambda a,b: a/b, x,y)).__lt__(2):
                                                        print("The sum of x and y is less than 2")
else:
       print("The sum of x and y is greater than 2.")
>>> 
The sum is greater than 2.
>>>


if statement sum(map(lambda).__le__()
The lambda returns with equation computation.
import math
x=[math.log(2,10),math.log10(22), math.log2(2)]
y=[math.trunc(2.1)]
if sum(map(lambda a,b: a+b/2, x,y)).__le__(y):
    print("The return is large or equal to 2.0")
else:
    print("The value does not meet the criteria")

>>> 
The return is large or equal to 2.0
>>>


if min(map(lambda(decimal,decimal)).__gt__()
The method returns with the minimum value in the sets equation set1/set2*set2 is greater than 2. 
from decimal import*
set1={Decimal(-1355).adjusted(),Decimal(-233.321).copy_negate(), Decimal(-23.99).exp()}
set2={ Decimal(2.0).fma(3,7),Decimal(1.1).log10()}
if min(map(lambda a,b: a/b*b, set1, set2)).__gt__(2):
        print("Return is greater than 2.")
else:
        print("Not within parameters")

>>> 
Return is greater than 2.
>>>       



if (map(lambda function, string).__sizeof__.__gt__()
The method returns that a string size is greater than 22.
 str="python centre research"
if (map(lambda x: x, str)).__sizeof__().__gt__(22):
    print(str.__str__())
else:
    print("The string bytes size is greater than 22.")

>>> 
python centre research
>>> 


if operator.truth()
Return with maximum and minimum degrees values:
import math
import operator

a=math.degrees(33)
b=math.degrees(22)
c=math.degrees(34)
d=math.degrees(13.1)
e=math.degrees(120)

tuple=(a,b,c,d,e)

g=min(tuple)
h=max(tuple)

if operator.truth(abs(a-b)>90):
    print("Minimum degrees value is: ", g)
    print("Maximum degrees value is: ", h)
    print("The difference between minimum and maximum degrees is less 90 Degrees which is: ", abs(g-h))
else:
    print("The difference between minimum and maximum degrees is less 90 Degree which is: ", abs(g-h))

>>> 
Minimum degrees value is:  750.5747116213784
Maximum degrees value is:  6875.493541569878
The difference between minimum and maximum degrees is less 90 Degree which is:  6124.9188299484995
>>> 


if operator.xor(a,b).__lt__()
The method binary bit value of a, not in b after applying the round() method to Decimal().conjugate() and Decimal().copy_abs()
import operator
from decimal import*

a=round(Decimal(33).conjugate())
b=round(Decimal(-133).copy_abs())

if operator.xor(a,b).__lt__(300):
    print(" Binary the bit set in", a, "not in" ,b, "is", operator.xor(a,b))
else:
    ValueError

>>> 
Binary the bit set in 33 not in 133 is 164
>>> 


def (Decimal attribute)....if Decimal ==True
The method returns with Decimal attribute test as through define function and if statement.
 from decimal import Decimal

def test (a,b,c,d,e,f,g,h,i):

    
    if a==True:
        print("The Decimal(",value1,")is canonical.")
    else:
        print("The Decimal(",value1,")is not canonical.")
        
       
    if b==True:
        print("The Decimal(",value2,")is finite.")
    else:
        print("The Decimal(",value2,")is not finite.")


    if c==True:
        print("The Decimal(",value3,")is infinite.")
    else:
        print("The Decimal(",value3,")is not infinite.")


    if d==True:
        print("The Decimal(",value4,")is nan.")
    else:
        print("The Decimal(",value4,")is not nan.")


    if e==True:
        print("The Decimal(",value5,")is normal.")
    else:
        print("The Decimal(",value5,")is not normal.")
              

    if f==True:
        print("The Decimal(",value6,")is signed.")
    else:
        print("The Decimal(",value6,")is not signed.")


    if g==True:
        print("The Decimal(",value7,")is snan.")
    else:
        print("The Decimal(",value7,")is not snan.")


    if h==True:
        print("The Decimal(",value8,")is subnormal.")
    else:
        print("The Decimal(",value8,")is not subnormal.")


    if i==True:
        print("The Decimal(",value9,")is zero.")
    else:
        print("The Decimal(",value9,")is not zero.")


value1=1.1
value2=-2.1
value3='infinity'
value4=0
value5=1.21
value6=10
value7=.50
value8=.12
value9=.21

test(value1,value2,value3, value4, value5,value6,value7, value8, value9)

>>> 
The Decimal( 1.1 )is canonical.
The Decimal( -2.1 )is finite.
The Decimal( infinity )is infinite.
The Decimal( 0 )is not nan.
The Decimal( 1.21 )is normal.
The Decimal( 10 )is not signed.
The Decimal( 0.5 )is not snan.
The Decimal( 0.12 )is not subnormal.
The Decimal( 0.21 )is not zero.
>>>


def....: if Entry().get()
The Entry.get() input text verified through Button(command).
from tkinter import*

master=Tk()
master.title("Login")

def validate1():
    if  entry.get()=="pythonlake":
        label1=Label(master, text="Welcome")
        label1.grid(row=0,column=3)
        entry.destroy()
        button.destroy()
        label.destroy()
    else:
        label2=Label(master, text="You are not authorized", background="red", fg="white")
        label2.grid(row=0,column=3)

label=Label(master, text="Enter your username: ")
label.grid(row=0,column=0)
           
entry=Entry(master)
entry.grid(row=0,column=1)

button=Button(master, text="Submit",command=validate1)
button.grid(row=0,column=2)

master.mainloop()








tkinter.Tk()
tkinter.Label().pack()
if..:print()
The method return with:
 from tkinter import Tk
import tkinter


a=tkinter.Label(master,text="hello").pack()

if a=="hello":
    print("Yes, tkinter.Label(master,text='hello').pack() is equal to 'hello'.")
    print("No, tkinter.Label(master,text='hello').pack() is not equal to 'hello'.")
    
master.mainloop()

>>> 
No, tkinter.Label(master,text='hello').pack() is not equal to 'hello'.
>>>
              
Comments