Skip to content

Instantly share code, notes, and snippets.

@joetechem
Created December 13, 2016 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joetechem/c80c51632b46d71d47f39c8157817792 to your computer and use it in GitHub Desktop.
Save joetechem/c80c51632b46d71d47f39c8157817792 to your computer and use it in GitHub Desktop.
a simple gist to show how you can use a for loop and create a variable to use that variable
# A simple program to demonstrate using a for loop
# To print hello world! five times in Python, you could type
# print('hello world!') five times, each on its own line
# Or, you could use a 'for loop' to have the same result with less typing:
for x in range (0, 5):
print('hello world!')
# The range function can create a list of numbers ranging from a starting number
# to the number just before the ending number.
# Create a variable then use that variable
name = 'name'
for x in range(0, 5):
print(name)
# OR
for i in range(5):
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment