Python
  Home arrow Python arrow Page 5 - 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? 
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 - Assignment Operators
    ( Page 5 of 5 )

    These little guys are what make it all worthwhile. You've already worked with the '=' assignment operator, which assigns a value. Now we will learn to work with the rest of these handy hooligans:


    #!/usr/local/bin/python

    beers = 20

    print beers

    beers +=5

    print beers

    beers -=5

    print beers

    beers *=10

    print beers

    beers /=10

    print beers

    beers **=5

    print beers

    beers %=9

    print beers

    The result of this is:

      20

      25

      20

      200

      20

      3200000

      5

    Note that in the above example we used all of what are called Augmented Assignment operators. If we said beers +=1 for example, what we are really saying is beers = beers + 1. In the above example that would mean beers value is now 21. The only augmenter we left out was the //= which would just have given a similar result to the /= (remember, for now the division operator truncates, but that will change in the future).

    And Lastly, Operator Precedence

    Operator Precedence determines in which order operations are evaluated. You can control this with parentheses(). Consider this:

    2+10*10 = 120 in normal math.

    2+ (10*10) = 102 because the parentheses gives precedence to the equation 10*10.

    That isn't all there is to say about operator precedence; there is a whole table's worth of operator precedence I could show you, but at the moment we are out of time and really, that table is quite boring.

    So come back often as we continue our death-defying discussion of...what were we talking about again? Oh yeah, Python.

    Till then...



     
     
    >>> 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 2 Hosted by Hostway
    Stay green...Green IT