Python‎ > ‎Control Flow‎ > ‎

def

Definition
Python allow to create our function to execute the parameters.

Syntax
def  function_statement(variables_x):
       variable defined 
       execution

Assignment variables_y to parameter
function_statement(variables_y)

Parameters
number & string

Examples

URLField is created through models and  viewed through index.html. 

Window CMD  commands 

  • virtualenv djangoschool
  • cd  djangoschool
  • .\Scripts\activate
  • pip install django
  • python .\Scripts\django-admin.py startproject mysite
  • cd mysite
  • python manage.py startapp myapp
  • python manage.py syncdb
  • python manage.py runserver




mysite/setting.py

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

mysite/urls.py

from django.conf.urls import include, url

from myapp.views import ViewUrl
urlpatterns = [
    url(r'^', ViewUrl)
]


myapp/models.py

from django.db import models

class ModelUrl(models.Model):
    url=models.URLField()

    def __str__(self):
        return self.url


myapp/forms.py

from django import forms
from .models import ModelUrl

class FormUrl(forms.ModelForm):
    class Meta:
        model=ModelUrl
        fields=['url']


myapp/views.py

from django.shortcuts import render

from django.shortcuts import HttpResponseRedirectHttpResponse
from .forms import FormUrl

def ViewUrl(request):
    form=FormUrl(request.POST)
    if form.is_valid():
        form.save(commit=False)
        form.save()
        return HttpResponseRedirect('/thanks/')
    else:
        form=FormUrl
    return render(request, 'myapp/index.html',{'form':form})

def response(request):
    return HttpResponse("Thanks")

myapp/index.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<form  action="/thanks/" method="post">

    {%csrf_token%}

    {{form}}

    <input type="submit">

</form>

</body>
</html>

Localhost:8000



Database Query




Here in this example, the CharField  is used to store the data into the field.  The data is recorded and saved in models.py and retrieved and displayed through the views.py. 
 Steps for creating virtual environment, startproject, startapp, creating database, and migrating the data, and running server to check the app.
  • virtualenenv djangoschool
  • cd djangoschool
  • .\Scripts\activate
  • pip install django
  • python .\Scripts\django-admin.py startproject mysite
  • python manage.py migrate
  • python manage.py startapp dbapp
  • python manage.py makemigrations dbapp


mysite/settings,py

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

mysite/urls.py

from django.conf.urls import include, url

from dbapp.views import Display

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

dbapp/models.py


    groups=(('male','0-40'),('female','0-40'))
    genderfield=models.CharField(max_length=50,choices=groups)

v=LongLife(genderfield="Casey")
v.save()

dbapp/views.py



from . models import LongLife

def Display (request):
    return HttpResponse(LongLife.objects.filter(genderfield="Casey").values())







Here, this example, mydb.db database is created and in that database Table3 is created with Fields, name, email, telephone and income. The values are displayed through for loop by order of income in html file.
Steps for creating virtual environment, startproject, startapp, creating database, and migrating the data, and running server to check the app.
  • virtualenenv pythonlake
  • cd pythonlake
  • .\Scripts\activate
  • pip install django
  • python .\Scripts\django-admin.py startproject mysite
  • python manage.py migrate
  • python manage.py startapp mydb
  • python manage.py makemigrations mydb




mysite/settings.py

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

mysite/urls.py


from mydb.views import DataBase
urlpatterns = [
    url(r'^$', DataBase),
]

mydb/views.py

from django.shortcuts import render

import sqlite3

def DataBase (request):
    conn=sqlite3.connect('mydb.db')
    cursor=conn.cursor()
    cursor.execute('''CREATE TABLE table3(name text, phone text, email text, income text)''')
    cursor.execute('''INSERT INTO table3 VALUES(' Erica ', ' 571 402 2992 ', ' erica.steve@ibm.com ', '  180000 ')''')
    cursor.execute('''INSERT INTO table3 VALUES(' Strube ', ' 571 402 2212 ', ' marya_strube@care.com ', ' 890000 ')''')
    conn.commit()

    for row in cursor.execute('SELECT * FROM table3 ORDER BY income'):
        response=row

    return render(request, 'mydb\index.html', {'response':response} )

mydb/index.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Table3</title>
</head>
<body>

{{response}}

</body>
</html>





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/







EXAMPLE
Here, the submit form is created through the django web framework using django.forms. The forms is handled through the HTML files in which the views.py variables data is processed. While views.py import the form fields from myapps/forms.py
Steps for creating steps for virtua 

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



Settings.py

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


mysite/urls.py

from django.conf.urls import url
from myapp.views import submit

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


myapp/forms.py

__author__ = 'adilwaseem75'

from django import forms

class CharField(forms.Form):
    username=forms.CharField()
    username.label="Username"
    username.max_length=50

class EmailField(forms.Form):
    email=forms.EmailField()
    email.label="Email"
    email.max_length=50


myapp.views.py

from django.shortcuts import render

from .forms import EmailField
from .forms import CharField

def submit(request):
    username=CharField()
    email=EmailField()

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

myapp.index.html

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

<form action="/Thank-you/" method="post">
    {% csrf_token %}
    {{username}} <br> <br>
    {{email}}<br><br>
    <input type="submit" value="Submit" />
</form>

</body>
</html>


Running the server through Window CMD command, python manage.py runserver





EXAMPLE
The django web framework returns with hyperlink created through html5 integrated with django Scripts.
Steps for creating virtual environment, startproject, startapps, migration, & running server:
    • virtualenv string
    • cd  string
    • .\Scripts\activate
    • pip install django
    • python .\Scripts\django-admin.py startproject str
    • cd str
    • python manage.py runserver
    • key ctr c to break the server
    • python manage.py startapp htmlapp
    • python manage.py runserver

    File structure 




    settings.py

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

    urls.py

    from django.conf.urls import url, patterns
    from htmlapp.views import html_links

    urlpatterns = patterns('',

        url(r'^html_links/', html_links),
        )

    httpapp/views.py


    def html_links(request):
        link='<div style="background-color:pink; color:white; padding:20px;">'\
             '<a href="http://www.pythonlake.com/">Python Lake</a> <hr>' \
             '<a href="http://www.pythonlake.com/python/django">Django</a> <hr> ' \
             '<a href="http://www.pythonlake.com/python/django/djangohttp">django.http</a> <hr> ' \
             '<a href="http://www.pythonlake.com/python/django/djangohttp/httpresponse">HttpResponse</a> <hr> ' \
             '</div>'
        return HttpResponse(link)


    Running the server through Window CMD command.







    The django web framework is used to create the application which convert the string into uppercase using str.upper method. The string_method_upper.py calls the string_method.views.py file to render the function.
    Windows CMD commands for creating virtualenv, startproject, startapp, and running server.
    • virtualenv string
    • cd string
    • .\Scripts\activate
    • pip install django
    • python .\Scripts\django-admin.py startproject str
    • cd str
    • python manage.py runserver
    • python manage.py startapp string_methods
    • python manage.py startapp string_method_upper
    • python manage.py runserver



    string_method_upper/views.py


    def string_method_upper (request):
        return string_upper(request)

    string_methods/views.py


    def string_upper(request):
        return HttpResponse("Python is a simple, powerful and high-level programming language "
                            "and the logic and structure is consistent with the way we "
                            "reasons. ".upper())


    urls.py

    from string_methods.views import*
    from string_method_upper.views import *

    urlpatterns=patterns('', url(r'^string_method_upper/', string_method_upper),)

    settings.py

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





    EXAMPLE
    The app is created to count the words in string using django web framework.
     Django Window CMD Commands
    Steps for creating virtual environment, startproject, startapps, migration, & running server:
    • virtualenv string
    • cd  string
    • .\Scripts\activate
    • .\Scripts\deactivate
    • pip install django
    • python .\Scripts\django-admin.py startproject str
    • cd str
    • python manage.py runserver
    • ctr c to stop server
    • python manage.py startapp string_methods
    • python manage.py migrate
    • python manage.py runserver
    FILE STRUCTURE
     
    In views.py file, the string value is added  by '%' expression to add str.count(). 
    from django.http import HttpResponse

    def count_chr(request):

        x="Python Lake is a project of OnRails LLC, founded by Adil Waseem with a mission to put all" \
          " Python Programming codes in one website with research findings for beginner, developer and " \
          "researcher to advance the development of Python. Internet is flooded with the Python codes but" \
          " all are deficient in comprehensiveness where we could find all functions in place with the" \
          " examples how and where to apply these. Python Lake will achieve this mission to promote learning" \
          " and research of Python without constraint by the lack of code examples and its application. " \
          "The site will be kept update periodically to allow students, developer and researcher them make" \
          " best of available resources in Python."
        y=x.count('Python')
        response = "Total words start with 'Python' in paragraphs are:%s"
        return HttpResponse(response%y)
     
    In settings.py file,  apps name is added.
    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles','string_methods'
    )
    In urls.py file, following code is added to allow the apps to import function from the views.py.
     from django.conf.urls import include, url
    from django.contrib import admin

    from string_methods.views import count_chr

    urlpatterns = [
        url(r'^string_methods/', count_chr),
    ]
     
    Viewing in the browser after running server through CMD command.
     
     


    The function calculated string 'turtle' in webpage in django.
    STEPS for creating virtual environment, startproject, startapps, migration, & running server.
    • virtualenv [virtual environment name]
    • cd  [virtual environment name]
    • .\Scripts\activate
    • .\Scripts\deactivate
    • pip install django
    • python .\Scripts\django-admin.py startproject [project name]
    • cd [project name]
    • python manage.py runserver
    • python manage.py startapp [name of app]
    • python manage.py migrate
    • python manage.py runserver
     After virtual environment, startproject, and startapp, the files structure look like this:


      In setting.py, put following intended app name, here it is newrequests.
      INSTALLED_APPS = (
          'django.contrib.admin',
          'django.contrib.auth',
          'django.contrib.contenttypes',
          'django.contrib.sessions',
          'django.contrib.messages',
          'django.contrib.staticfiles','newrequests',
      )

      In urls.py, put following code: 
      from django.conf.urls import include, url
      from django.contrib import admin

      from newrequests.views import request1

      urlpatterns = [
          url(r'^newrequests/$', request1),
      ]

      In views.py, put following code:
      from django.http import HttpResponse
      import requests

      def request1(request):
          r=requests.get('http://www.pythonlake.com/Python/turtle')
          c=r.text
          ct=c.count('turtle')
          return HttpResponse(ct)
       
      Running the server at localhost:8000 through following command in CMD:
       python manage.py runserver



      Here HttpResponse returns with value of pow() through django web framework.
      STEPS for creating virtual environment, startproject, startapps, migration, & running server.
      • virtualenv [virtual environment name]
      • cd  [virtual environment name]
      • .\Scripts\activate
      • .\Scripts\deactivate
      • pip install django
      • python .\Scripts\django-admin.py startproject [project name]
      • cd [project name]
      • python manage.py runserver
      • python manage.py startapp [name of app]
      • python manage.py migrate
      • python manage.py runserver
       After virtual environment, startproject, and startapp, the files structure look like this:


        In setting.py, put following app name, here it is powapp.
        INSTALLED_APPS = (
            'django.contrib.admin',
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.messages',
            'django.contrib.staticfiles','powapp',
        )

        In urls.py, put following code: 
        from django.conf.urls import include, url
        from django.contrib import admin

        from powapp.views import func_pow

        urlpatterns = [
            url(r'^powapp/$', func_pow),
        ]

        In views.py, put following code:
        from django.shortcuts import render
        from django.http import HttpResponse

        def func_pow(request):
            return HttpResponse(pow(4,5))
         
        Running the server at localhost:8000 through following command in CMD:
         python manage.py runserver


        The FileResponse returns with png file from disk.
        from paste.httpserver import serve
        from pyramid.view import view_config
        from pyramid.config import Configurator
        from pyramid.response import FileResponse

        @view_config(route_name='png')
        def turtle(file):
            view = FileResponse(
                'turtle.png',
                request=file,
                content_type='image/png'
                )
            return view

        if __name__ == '__main__':
            config = Configurator()
            config.add_route('png', '/')
            config.scan('__main__')
            serve(config.make_wsgi_app())





        The html code are integrated inside the pyramid.response.Response().
        from wsgiref.simple_server import make_server
        from pyramid.config import Configurator
        from pyramid.response import Response

        def html(request):
            return Response(
                '<a href="http://www.pythonlake.com/">Python Lake</a>'
                '<hr>'
                '<a href="http://www.pythonlake.com/aboutus">About us</a>'
                '<hr>'
                '<a href="http://www.pythonlake.com/appointment">Appointment</a>'
                '<hr>'
                '<a href="http://www.pythonlake.com/contactus">Contact us</a>')
            
        if __name__ == '__main__':
            config = Configurator()
            config.add_route('links', '/')
            config.add_view(html, route_name='links')
            app = config.make_wsgi_app()
            server = make_server('0.0.0.0', 1000, app)
            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 goto(x,y) position is changed through the for loop value.
        import turtle
        import random

        def random_colors(click_x, click_y):
               
            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.bgcolor("black")
            turtle.pensize(4)
            turtle.penup()
            click = turtle.goto(click_x, click_y)
            turtle.pendown()
            turtle.speed(50)
          
            for i in range(0,20):
                colors=random.sample(color_list,1)
                click = turtle.goto(click_x+i*5, click_y+i*5)
                turtle.begin_poly()
                turtle.begin_fill()
                turtle.color(colors)
                turtle.circle(100-i*5)
                turtle.right(90)
                turtle.end_fill()
                turtle.end_poly()
                
            colors=random.sample(color_list,1)
            turtle.color(colors)
            turtle.pensize(10)
            turtle.left(45)
            turtle.forward(25)
            
            h='Butterfly', turtle.xcor(), turtle.ycor()
            turtle.title(h)
            return click


        turtle.onscreenclick(random_colors)




        Here random function is executed through onscreenclick in turtle screen.
        import turtle
        import random

        def random_colors(click_x, click_y):
               
            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.pensize(4)
            turtle.penup()
            click = turtle.goto(click_x, click_y)
            turtle.pendown()
            turtle.speed(50)
            x=(random.randrange(45,50))
          
            for i in range(0,10):
                colors=random.sample(color_list,1)
                turtle.begin_fill()
                turtle.color(colors)
                turtle.circle(x-i)
                turtle.end_fill()
                    
            h='x & y position is', turtle.xcor(), turtle.ycor()
            turtle.title(h)
            return click


        turtle.onscreenclick(random_colors)



         


        The random.randrange(a,b) is used to generate values for the creation of  line.
        from tkinter import *

        master = Tk()
        master.title("Random line draw")

        def line():
            import random
            x1=random.randrange(0,300)
            y1=random.randrange(0,300)
            x2=random.randrange(0,300)
            y2=random.randrange(0,300)
            canvas.create_line(x1, y1, x2, y2)

           
        canvas = Canvas(master, width=300, height=300)
        canvas.pack(side=TOP)

        button=Button(master, text="Click to draw random line", command=line).pack(fill=BOTH)

        master.mainloop()





        The tkinter.Canvas create polygon method is used to create the random polygon point values and color is filled through random.sample method.
         
        from tkinter import *

        master = Tk()
        master.title("Python Lake: Create random Polygons")

        def line():
            import random
            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']


            for i in range(0,200):
                x1=i+random.randrange(0,300)
                y1=i+random.randrange(0,300)
                x2=i+random.randrange(0,300)
                y2=i+random.randrange(0,300)
                x3=i+random.randrange(0,300)
                y3=i+random.randrange(0,300)
                x4=i+random.randrange(0,300)
                y4=i+random.randrange(0,300)
                x5=i+random.randrange(0,300)
                y5=i+random.randrange(0,300)
                x6=i+random.randrange(0,300)
                y6=i+random.randrange(0,300)
                
                pt=[x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6]
                
                color=random.sample(color_list,1)
                canvas.create_polygon(pt, outline=color, fill=color)
                
               
        canvas = Canvas(master, width=500, height=500, background="black")
        canvas.pack(side=TOP)

        button=Button(master, text="Click here to create random polygons", command=line).pack(fill=BOTH)






        The for loop generate the ovals through  values generated by random methods.
        from tkinter import *

        master = Tk()
        master.title("Click to generate random ovals")

        def bpress(click):

            import random
            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']


            for i in range(0,1000):

                x1=click.x-(random.betavariate(3,1)+(random.gammavariate(3,10)))
                y1=click.y-((random.betavariate(3,1))+(random.gammavariate(3,6)))
                x2=click.x+(random.normalvariate(19,3))
                y2=click.y+random.randrange(0,20)
                color=random.sample(color_list,1)
                canvas.create_oval(x1,y1,x2,y2, fill=color)

                        
        canvas = Canvas(master,width=500, height=500, background="black" )
        canvas.pack(expand = YES)
        canvas.bind( "<ButtonPress>", bpress )

        master.mainloop()






        The button command function is used to invoke the message box to display the random value.
        from tkinter import*

        master = Tk()
        master.title("Random Widget")

        def random_value():
            import random
            random1=random.random()
            messagebox.showinfo("Random Value is", random1)

        labelframe=LabelFrame(master, fg="red", font=14, text="Random value generator")
        labelframe.pack(side=BOTTOM)

        button = Button(labelframe, text = "Click here", fg="blue", command = random_value)
        button.pack(side=BOTTOM)

        label = Label(labelframe, text = "Click on button to generate random value")
        label.pack(side=BOTTOM)

        master.mainloop()






        The tkinter Button generated the Random number through Random.random() method.
         >>> from tkinter import*
        >>> master=Tk()
        >>> def Random_number():
                        import random
                        random1=random.random()
                        print(random1)
        >>> button=Button(master, text="Generate Random Number", command=Random_number).pack()





        >>> 0.3113241804334048
        0.5353597978093854
        0.6206780899289036
        0.1329108837599009
        0.09253008814720265
        0.7965295953913955
        0.5464788670836471
        0.05573566853264078
        0.5957291155959824
        0.5136834489919084
        0.24383631011415896
        0.8615995927200537


        The frame "<ButtonRelease>" trigger the function(buttonrelease) which displays the Label(welcome).
        from tkinter import *

        master = Tk()

        def buttonrelease(click):
            label=Label(frame, text="Welcome", fg="Blue")
            label.pack(side=TOP)

        frame = Frame(master, background="blue", width=200, height=200)
        frame.bind("<ButtonRelease>", buttonrelease)
        frame.pack()

        master.mainloop()








        The ButtonPress triggers the event which created new Tk widget while destroyed main Widget.
         from tkinter import*
        import tkinter

        def widget_Tk(buttonpress):
            master=Tk()
            master.title("Click Widget")
            master1.destroy()
            
        master1=Tk()
        master1.title("Main Widget")
        master1.bind("<ButtonPress>", widget_Tk)

        master1.mainloop()









        The tkinter.Entry is used to check the string characteristics through string methods.

        master=Tk()
        master.title("String methods")

        def cap():
            try:
                c=str.capitalize(s.get())
                s.set(c)
                
                pass

        def cfold():
            try:
                c=str.casefold(s.get())
                s.set(c)
                
            except ValueError:
                pass

        def ifier():
            try:
                if str.isidentifier(s.get())==True:
                    s.set("Yes")
                
                else:
                    s.set("No")
                
            except ValueError:
                pass

        def ipace():
            try:
                if str.isspace(s.get())==True:
                    s.set("Yes")
                
                else:
                    s.set("No")

            except ValueError:
                pass

        def iric():
            try:
               if str.isnumeric(s.get())==True:
                   s.set("Yes")
               else:
                   s.set("No")        
                        
            except ValueError:
                pass

        def ower():
            try:
                if str.islower(s.get())==True:
                    s.set("Yes")
                
                else:
                    s.set("No")        
                
            except ValueError:
                pass

        def inum():
            try:
                if str.isalnum(s.get())==True:
                    s.set("Yes")
                
                else:
                    s.set("No")        
            except ValueError:
                pass

        def imal():
            try:
                if str.isdecimal(s.get())==True:
                    s.set("Yes")
                
                else:
                    s.set("No")
                
            except ValueError:
                pass

            

        def igit():
            try:
                if str.isdigit(s.get())==True:
                    s.set("Yes")
                
                else:
                    s.set("No")
                
            except ValueError:
                pass


        def clr():
            try:
                s.set("")
                
                      
            except ValueError:
                pass



        entry=Entry(master, textvariable=s)
        entry.grid(row=0, columnspan=4, sticky=W+E)


        button_capitalize=Button(master, text="capitalize", width=10, command=cap)
        button_capitalize.grid(row=2, column=0)

        button_casefold=Button(master, text="casefold",width=10, command=cfold)
        button_casefold.grid(row=2, column=1)

        button_isidentifier=Button(master, text="isidentifier",width=10,command=ifier)
        button_isidentifier.grid(row=2, column=2)


        button_isspace=Button(master, text="isspace",width=10, command=ipace)
        button_isspace.grid(row=3, column=0)

        button_endswith=Button(master, text="endswith", width=10, command=iric)
        button_endswith.grid(row=3, column=1)

        button_islower=Button(master, text="islower",width=10, command=ower)
        button_islower.grid(row=3, column=2)



        button_isalnum=Button(master, text="isalnum",width=10, command=inum)
        button_isalnum.grid(row=4, column=0)

        button_isdecimal=Button(master, text="isdecimal",width=10, command=imal)
        button_isdecimal.grid(row=4, column=1)

        button_isdigit=Button(master, text="isdigit",width=10, command=igit)
        button_isdigit.grid(row=4, column=2)

        button_clear=Button(master, text="Clear", command=clr )
        button_clear.grid(row=5, columnspan=3,sticky=W+E)












        def....: 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()








        There simple mainloop widget(). 
        import tkinter
        class maintloop1():
            def __init__(self,a):
                self.a=a
                a.mainloop()

        x=tkinter.Tk()
        maintloop1(x)






        def print1 :....... tkinter.button(command=print1)
        The button command executed the def print1.
        from tkinter import*
        import tkinter
            

        def print1():
            tkinter.Label(master,text="Thank you").pack()

        frame=tkinter.Label(master,text="Python Lake: Welcome").pack()

        button=tkinter.Button(master, text="Submit", command=print1).pack()

        master.mainloop()





        Def...(): tkinter
        The code create the text() through button and then destroy and created new buttom compose.
        from tkinter import*
        from tkinter import Text
        import tkinter
            
        master=tkinter.Tk()

        def message():
            compose_button.destroy()

            send_message_button=tkinter.Button(master, text="Submit Message")
            send_message_button.pack()
              
            compose_text=tkinter.Text(master)
            compose_text.pack()
            


        compose_button=tkinter.Button(master, text="Compose Message",command=message)
        compose_button.pack()


        master.mainloop()











        Def...:tkinkter.Entry().destroy()
        The method  Erase text, delete Entry, and destroy the widget() through Button(command)
        from tkinter import*

        master=Tk()

        def e1_delete():
            e1.delete(first=0,last=100)

        def master_destroy():
             master.destroy()
            

        def entry_destroy():
            e1.destroy()
            

        e1=Entry(master, width=35)
        e1.pack()


        b_erase=Button(master, text="Erase", command=e1_delete)
        b_erase.pack()

        b_quit_destroy=Button(master, text="Quit", command=master_destroy)
        b_quit_destroy.pack()


        b_delete_text=Button(master, text="Delete Entry", command=entry_destroy)
        b_delete_text.pack()


        master.mainloop()


         






        class.....: def....: str.count()
        The function find the number of vowels in the name through input() through str.count().
         class string_methods:
            def __init__(self,a,b):

                 
                va=a.count("a")
                ve=a.count("e")
                vi=a.count("i")
                vo=a.count("o")
                vu=a.count("u")
                

                count_a=va+ve+vi+vo+vu

                print("Total vowels in your first name are:",count_a) 

                va=b.count("a")
                ve=b.count("e")
                vi=b.count("i")
                vo=b.count("o")
                vu=b.count("u")
                

                count_b=va+ve+vi+vo+vu

                print("Total vowels  in your last name :",count_b)


                print("Total vowels in your full name:", count_a+count_b)
                
                
        first_name=input("Please enter your first name: ")
        second_name=input("Please enter your second name: ")


        string_methods(first_name,second_name)


        >>> 
        Please enter your first name: adil
        Please enter your second name: waseem
        Total vowels in your first name are: 2
        Total vowels in your last name : 3
        Total vowels in your full name: 5
        >>>



        class....: def....: str.find()...str.count
        The function allow the user to find word in their text.
         class method_text_finder():
            def __init__(self, a,b):

                self.a=str(a)
                find1=a.find(b)
                print("The word found in your text at position:",find1+1)

                count1=a.count(b)
                print("The total word found in your text:",count1)

        text=input("Please enter your text: ")
        find_word=input("Please enter your text:")

        method_text_finder(text,find_word)

        >>> 
        Please enter your text: Python Research Centre is located at Woodbridge Va
        Please enter your text:Woodbridge
        The word found in your text at position: 38
        The total word found in your text: 1
        >>> 


        class.....: def __init__()......:....str.isidentifier().....str.lower()....str.isapha()
        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
        >>>        


        The return is:
        def box(x,y,z):
        print(x,y,z)

        box(1,2,11)

        >>> 
        1 2 11
        >>> 

        The function returns as:
        def box(x,y,z):
            x=x+1
            y=y+1
            z=z+1
            a=x+y+z
            
            print(a)

        box(1,2,11)

        >>> 
        17
        >>> 

        def (Decimal attribute)
        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.
        >>>


        itertools.dropwhile(function, iterable)
        The equal to:
         def function1(x):
        x>5
        list(itertools.dropwhile(function1, [1,2,3,4]))
        >>>
        [1, 2, 3, 4]
        >>>


        The return is:
         from itertools import *
        def takewhile1(x):
        return x<15

        list=[1,3,5,7,9]
        for i in takewhile(takewhile1, list ):
        print (i)

        >>> 
        1
        3
        5
        7
        9
        >>>


        class name: def....:
        The method return with the value of box.
         class box:
            def __init__(self, h, w):
                self.x = h
                self.y = w
        z = box(3.0, -4.5)
        z.x*z.y
        print(z.x*z.y)

        >>> 
        -13.5
        >>> 

        class...:def..:
        The method return with the round() value of the parameter.
        class round_value:
            def __init__(self,a):
                self.x = round(a)
                
        value=33.22
        z=round_value(value)
        output=z.x

        print(output)

        >>> 
        33
        >>> 


        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...:
        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
        >>>


        The my Function() call the Afunc() and execute the print method. 
         def Afunc(a):
           print(len(a))

        def my_function(a, b, c,d):
          print(a)
          print(c)
          print(c+2)
          Afunc(d)

        my_function(2,3,3,"Adil Waseem")
         2
        3
        5
        11


        Comments