Python‎ > ‎Built-in‎ > ‎

pow()

http://www.adilwaseem.com/

Definition
With two arguments, equivalent to x**y. With three arguments, equivalent to (x**y) % z, but may be more efficient (e.g. for ints).

Syntax
pow(...)
pow(x, y) -> number

Parameters
x, y=numbers

Examples
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


    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 method return with first raised to power of second.
     >>> 
    >>> pow(2,3)
    8
    >>> 

    pow()__inv__
    The method pow(a,b) inside __inv__().
    >>> operator.__inv__(pow(2,3))
    -9

    pow()__add__
    The value added through __add__:
     >>> import operator
    >>> a=operator.ipow(3,4)
    >>> b=pow(3,4)
    >>> a.__add__(b)
    162

    pow()__gt__()
    Testing equality between method through __gt__:
     >>> import operator
    >>> a=operator.ipow(3,4)
    >>> b=pow(3,4)
    >>> a.__gt__(b)
    False

    pow()__eq__()
    The equality is tested in in __eq__ method:
     >>> import operator
    >>> a=operator.ipow(3,4)
    >>> b=pow(3,4)
    >>> a.__eq__(b)
    True

    lambda(pow())
    The method return with the equality test whether the max() of the map() is equal to pow(23, 3).
    x=(11,23,444,333)
    y=max(map(lambda a: a, x)).__eq__(pow(22,3))
    print(y)
    >>> 
    False
    >>>

         
    Comments