Python

Data Structures

and

Style Guide


Week 4

for the course

An Introduction to Interactive Programming in Python


What am I gonna talk about?


  1. Lists

  2. Tuples

  3. Functions

  4. PEP


Python 
Enhancement Proposals



PEP 8

Style guide for Python

Imports


# BADimport simplegui, math
# GOOD
import simpleguiimport math
# FINEfrom math import sqrt, pi

Indentation


# BAD
def foo():
  print "My indentation sucks"


# GOOD
def bar():
    print "My indentation rocks"

White spaces

# WHITESPACES - 1

sqrt (2)    # BAD
sqrt(2)     # GOOD
# WHITESPACES - 2

# BAD
x=1
y   = 1
z = 3*2

# GOOD
x = 1
y = 1
z = 3 * 2
spacing_matter = True


PEP 257

Docstring conventions

One line Docstring

 def pow(x, y):
	"""Returns the yth power of x"""
    return x ** y


Multi line Docstring

def pow(x, y):
    """
    This is a very stupid function which returns the yth power of x
    
    Positional Arguments
    x -- number
    y -- index
    
    """
    return x ** y


PEP 20

The Zen of Python


Thank You 

:)


Twitter: @decached

Github: @decached


"First solve the problem. Then write the code" - John Johnson

Pacman Style

By Akash Kothawale