Created
May 10, 2017 20:36
-
-
Save prasanjit-/c205e89c48eca072ada4b6b93e3b9511 to your computer and use it in GitHub Desktop.
python-basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The hash sign tells Python to ignore the rest of this line. | |
# This way, we can write 'comments' that tell us stuff about code, | |
# but do nothing to the program. | |
# Print some stuff to the screen, on separate lines. | |
print(5) | |
print("hello") | |
print(2.5) | |
# Store some values with a name. Let's store '5' with the name 'x'. | |
x = 5 | |
print(x) # same as writing print(5) | |
# x is called a 'variable', since its value can vary. | |
x = 5 + 1 # x = 6 now | |
x = x + 1 # x = 7 now | |
# Make a choice here. | |
if x < 5: | |
print("x is less than 5!") | |
else: | |
print("Guess not, idiot.") # x >= 5, so this gets printed | |
# Print numbers from 0 to 5, noninclusive. | |
for i in range(5): | |
print(i) | |
# Print something 'x' times. | |
for i in range(x): | |
print("Printing again and again!") | |
# Name a chunk of code, so we can reuse it alot. | |
# Do this with the 'define', or 'def', keyword. | |
# This named chunk of code is called a 'function'. | |
def some_code(): | |
print("A thing") | |
some_code() # Prints "A thing". | |
some_code() # And again. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment