Python
  Home arrow Python arrow Python: Input and Variables
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? 
PYTHON

Python: Input and Variables
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    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:
      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


    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
     

       

    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
    Stay green...Green IT