Python
  Home arrow Python arrow Page 4 - Introduction to Python Programming
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

Introduction to Python Programming
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    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:
      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


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



     
     
    >>> 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
    For more Enterprise Application Development news, visit eWeek