Python
  Home arrow Python arrow Page 4 - 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? 
Google.com  
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 - For Loop
    ( Page 4 of 4 )

    The For Loop will loop for every value you have in a list. Here is a sample:


    #!/usr/local/bin/python


    for letter in “James”:

    print letter

    This code will loop until every letter of James is printed out, like so:

      J

      A

      M

      E

      S

    Pretty simple right? Let's involve the user more:


    #!/usr/local/bin/python


    user_name = raw_input(“Enter your name: “)


    for letter in user_name:

    print letter

    If the users name is something like Javier, it will print out:

      J

      A

      V

      I

      E

      R

    And that is it for loops in Python. There are no Do While loops as in other languages.

    Conditional Statements

    Sometimes in programming you need to ask certain questions and have the program respond accordingly. You can do so with conditional statements. Basically the way they work is this: "If this, then that." They get more complicated of course. You also can say "If this happens, do this, else do that." Or even "If this and That, or This or That, then do this else do that or that."

    I hope that is confusing, because this is the end of the article, and I want to ensure you return to enlighten yourself when I write the next episode on Python Conditionals.

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