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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PYTHON

Python Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek