Python
  Home arrow Python arrow Page 2 - Python Operators
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Python Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-01-14

    Table of Contents:
  • Python Operators
  • The Prestigious Mathematical Operators
  • The Judgmental Comparison Operators
  • Boolean is Not a Type of Broth
  • Assignment Operators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Python Operators - The Prestigious Mathematical Operators


    (Page 2 of 5 )

    Most of the mathematical operators you should be familiar with, at least if you graduated the third or fourth grade, which judging by that confused look on your face, perhaps you haven't. That's okay. I'll use little words.

    In the example below we will use each of math operators to demonstrate how they function:


    #!/usr/local/bin/python

    print "Here is an example of using addition: 2+2 =", 2+2

    print "Here is an example of subtraction: 4-2 =", 4-2

    print "Here is an example of multiplication: 2*4 =", 2*4

    print "Here is an example of division: 8/4 =", 8/4

    print "Here is an example of truncated division: 5//3 =", 5//3

    print "Here is an example of using powers: 2**9 =", 2**9

    print "Here is an example of using modulos: 5%3 =", 5%3

    The result of this code is:

      Here is an example of using addition: 2+2 = 4

      Here is an example of subtraction: 4-2 = 2

      Here is an example of multiplication: 2*4 = 8

      Here is an example of division: 8/4 = 2

      Here is an example of truncated division: 5//3 = 1

      Here is an example of using powers: 2**9 = 512

      Here is an example of using modulos: 5%3 = 2

    A few things to note: presently, division works the same as truncated division, though this will change in the future. Truncated division means that if you divide two integers, and the result is say, 1.25, then the program will round down to 1.

    Regarding Modulos, it is used to return the remainder of a division. In the above example we divide five by three, which is 1 with a remainder of 2. So thus, and thusly, modulos would return 2.

    More Python Articles
    More By James Payne


       · Thanks for stopping by and reading my article on Python Operators. Here we discuss...
       · Well not that I know a durn thing about Python, but it appears to me beers = 99 on...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway