Created
March 16, 2016 11:44
-
-
Save nicr9/5a5408f50a5515cea582 to your computer and use it in GitHub Desktop.
Python Cheat Sheet
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
# 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