Skip to content

Instantly share code, notes, and snippets.

@nicr9
Created March 16, 2016 11:44
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 nicr9/5a5408f50a5515cea582 to your computer and use it in GitHub Desktop.
Save nicr9/5a5408f50a5515cea582 to your computer and use it in GitHub Desktop.
Python Cheat Sheet
# Comments use the hash symbol
# some data types are similar to VB but names are either short or different
int # Plain numbers
float # Fractional numbers with floating point (similar to Double in VB)
str # String of text
bool # Boolean value (True or False)
# Creating a variable
x = 1
y = 3.14
z = "Hello world"
a = True # Note here that true is capitalised, the same counts for False
# Instead of arrays, python has lists which can hold any type (including other lists)
x = [1, 2, 3.14, "blah", False]
# Ask user for value
name = raw_input("What is your name?")
# If, else if (elif) and else
if ...:
...
elif ...:
...
else:
...
# While loop
while ...:
...
# For loop
for value in my_list:
...
# Exception handling
try:
...
except:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment