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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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 - 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...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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...
       · You wrote:2+10*10 = 120 in normal math.2+ (10*10) = 102 because the...
     

       

    PYTHON ARTICLES

    - 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
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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