Python
  Home arrow Python arrow Python: Input and Variables
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 Rational Software Development Conference
 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: Input and Variables
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-11-19

    Table of Contents:
  • Python: Input and Variables
  • Beating...I Mean Asking the User for Information
  • Loops
  • For Loop

  • 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

    Dell PowerEdge Servers

    Python: Input and Variables
    (Page 1 of 4 )

    In our last article we covered the history of Python, the print command, working with strings and variables, and how to comment your code. In this episode we will learn how to retrieve input from users, work with variables, and if you are lucky, Loops.

    So arise young knight and join me as we search for the Holy Grail of programming!

    Variables Vary Very Vivaciously

    The easiest way to describe a variable is to think of a box that holds information. You can store data in the box, you can take data out of the box and you can put different data in the box. Heck, if you don't get a programming job after reading this series, you can even live in a box.

    Here is how you work with variables in Python:


    #!/usr/local/bin/python


    sometext = “I like to eat grits.”


    some_number = 127


    anothernumber = 113


    totalnumbers = some_number + anothernumber


    print sometext

    print some_number

    print totalnumbers

    print some_number + anothernumber

    print “some_number plus anothernumber is”, some_number + anothernumber

    print sometext * 5

    In the above example we create variables by assigning them a name and a value (i.e. sometext = “I like to eat grits”). We then print them out. Here is the output:

      I like to eat grits.

      127

      150

      150

      some_number plus anothernumber is 150

      I like to eat grits. I like to eat grits. I like to eat grits. I like to eat grits. I like to eat grits.

    The code above should be mostly self-explanatory. The exception would be the statement: print sometext * 5. Because sometext holds a string value and not a mathematical one, the program writes the text contained in the sometext variable five times. When the * symbol is used in this manner it is known as the Repetition operator.

    More Python Articles
    More By James Payne


       · Hey thanks for dropping by and reading my article on Python. Its a pretty cool...
       · In your demonstration of a while loop, you wrote the following:"Next it creates...
     

       

    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 5 hosted by Hostway