Python
  Home arrow Python arrow Page 4 - Introduction to Python Programming
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 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

Introduction to Python Programming
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2007-11-12

    Table of Contents:
  • Introduction to Python Programming
  • No one expects the Spanish Inquisition!
  • Working with Numbers
  • Python Mathematical 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

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Help Simplify Virtualization by IBM

    Introduction to Python Programming - Python Mathematical Operators
    (Page 4 of 4 )

    Here is a pretty table listing the Mathematical Operators in Python:

     

    Operator

    Symbol

    What it Does

    Addition

    +

    2+2 == 4

    Subtraction

    -

    4-4 == 0

    Division

    /

    12 / 3 == 4

    Multiplication

    *

    2 * 4 == 8

    Exponentiation

    **

    10 ** 2 == 100 (Basically you are saying 10 times 10; if you wrote 10 ** 3 it would be 10 times 10 times 10 or 1000)

    Remainder or Modulus

    %

    Returns the remainder from a division. 17 % 4 == 1. If there is no remainder, the value would be 0. Ie; 16 % 4 == 0.

    Also, when working with math note that if you do not enter an equation in as a decimal, the result will not have a decimal. So if I said 14 / 3, it would give me the result of 4. If I used the expression 14.0 / 3.0 it would return 4.66666666667. In addition, you give mathematical equations precedence by using parentheses(). So: 3 * 2 + 2 would equal 8, whereas 3 * (2+2) would equal 12. This is because Python sees the parentheses and knows to calculate that portion first, then multiply by 3.

    Commenting

    You may have noticed earlier that I used the # symbol followed by some text. This is known as a comment. When Python sees the # it gets scared and runs away to the next line. It won't even read what you have written. Comments are used to leave notes for yourself or other programmers who may eventually view your code. They are typically used to describe what a particular snippet of code does. That way when you view your code six years later at four A.M. you don't rip your arm hair out trying to remember what the heck that function was supposed to do.

    Well that is it for this episode. In our next action-packed show, we will discuss how to get data from the user and how to use it, and my good buddy the variable. As always, thanks for dropping in and hope to see you soon.

    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.

       · Hey thanks for dropping by for this exciting episode of...Pigs...in...Space! Well...
     

       

    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...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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