Python
  Home arrow Python arrow Page 2 - Python 101 (part 2): If Wishes Were Py...
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
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 101 (part 2): If Wishes Were Pythons
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2001-05-31

    Table of Contents:
  • Python 101 (part 2): If Wishes Were Pythons
  • Tax Evasion
  • Q
  • Sliced And Diced
  • Comparing Apples And Oranges
  • If Only...
  • Tying Up The Loose Ends
  • Cookie-Cutter Code
  • Time For Lunch

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Python 101 (part 2): If Wishes Were Pythons - Tax Evasion


    (Page 2 of 9 )

    The first - and simplest - object type you're likely to encounter is the number. I've already shown you a few examples of how Python treats numbers last time - but here's a quick refresher anyway:

    Python 1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731 (experimental)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> print 24+1 25 >>> print 12*10 120 >>> print 65/5 13 >>> print 15-9 6 >>>
    There are four basic number types available in Python:

    Integers: These are plain-vanilla numbers like 23, 5748, -947 and 3; they are also the most commonly-used type.

    Floats: These are typically decimal numbers, although Python also allows you to use the scientific notation to represent them - for example, 3.67, 98.573 or 5.347e-17.

    Long integers: These are integer values which are too large to be handled by the regular Integer type - for example, 45734893498L or 53267282982L. Note the uppercase "L" appended to the end of a long integer, which makes this type easier to identify.

    Complex numbers: You may remember these from algebra class (I don't, but that's probably because I slept my way through college) - 2.5+0.3j, 4.1-03.j and so on. These numbers can be broken up into "real" and "imaginary" parts...the "imaginary" part is what you bank, while the "real" part is what the government takes away in taxes.{mospagebreak title=Putting Two And Two Together} Most of the time, you'll be working with integers and floats; the other two types are typically used for specialized applications. And as the example above demonstrates, Python allows you to add, multiply, divide and otherwise mess with these numbers via simple arithmetic operators. Here's an example which demonstrates the important ones:

    >>> alpha = 10 >>> beta = 2 >>> # standard stuff ... sum = alpha+beta >>> sum 12 >>> difference = alpha-beta >>> difference 8 >>> product = alpha*beta >>> product 20 >>> quotient = alpha/beta >>> quotient 5 >>> # non-standard stuff ... remainder = alpha%beta >>> remainder 0 >>> exponent = alpha**beta >>> exponent 100 >>>
    As with all other programming languages, division and multiplication take precedence over addition and subtraction, although parentheses can be used to give a particular operation greater precedence. For example,

    #!/usr/bin/python print(10 + 2 * 4)
    returns 18, while

    #!/usr/bin/python print((10 + 2) * 4)

    returns 48.

    It should be noted at this point that Python does not support the popular auto-increment (++) and auto-decrement (--) operators you may have used in Perl, PHP and JavaScript.

    There are also some built-in functions you can use with Python numbers - the most useful are abs() and pow(), which return the absolute value of a number and raise one number to the power of another. Take a look.

    >>> alpha = -89 >>> abs(alpha) 89 >>> pow(3,2) 9 >>>

    More Python Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

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




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