Skip to content

Instantly share code, notes, and snippets.

@nuclearsandwich
Created May 10, 2013 06:59
Show Gist options
  • Save nuclearsandwich/5552845 to your computer and use it in GitHub Desktop.
Save nuclearsandwich/5552845 to your computer and use it in GitHub Desktop.
Variables, strings, arithmetic, and concatenation in Python.
num1 = 5
num2 = 7
addition = num1 + num2
subtraction = num2 - num1
multiplication = num1 * num2
division = num2 / num1 # rounds down for integer division
print(addition) # prints 12
print(subtraction) # prints 2
print(multiplication) # prints 35
print(division) # prints 1
string1 = "hello"
string2 = "world"
addition = string1 + string2
print(addition) # prints "helloworld" (sticks strings together
subtraction = string1 - string2 # gives an error, subtraction/multiplication/division doesn't make sense for strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment