PEP

Python Enhancements Proposal (guidelines)
PEP 8: Style Guide For Python Code
PEP 20: Zen of Python

Indentation

Used to mark blocks, curly braces no longer needed
Recommendation is to use 4 spaces for indentation, be
consistent and not to mix spaces with tabs

Modules

 Use modules available in Python
e.g.: import math
After importing use the module name to call functions:
math.sqrt(5)
math.factorial(5)
from math import factorial > factorial(5) # avoid
using math
from math import factorial as fac > fac(5) #shorter
name

Help (in REPL cmd)

 Get help on a module
help(math)
 Get help on a function
help(math.sqrt)
help(math.factorial)

int, float

int(10), int(10.2), int(“10”)
float(10), float(10.2), float(“10.2”)

float(“nan”) # not a number
float(“inf”) # infinity


None

Represents absence of value
a = None
a Is None # returns True

Boolean

0: falsy
Nonzero (inc. negative): truthy
bool(0) bool(0.0): # False
bool(1) # True
For Lists
If list is empty: bool(list) returns False
bool([]) # False
bool([1,2,3]) # True
For strings:
bool(“”) # False
bool(“a”) # True
bool(“ “) # all
white spaces, True
if “ihavesomething”:
# this is True
print(“this is
True”)

Raw strings

path = r’C:\Users\Documents\Course’

Wednesday, 5 July 2017
Python 101  Part 1
Wednesday, 1 February 2017
CFA Level 2
Now on to CFA Level 2  June 3rd 2017.
I really love this period of preparing for something worthwhile  which requires your full dedication, focus and attention. It's almost as if you become one with your goal.
Edit [26July2017]:
And I cleared it !
I really love this period of preparing for something worthwhile  which requires your full dedication, focus and attention. It's almost as if you become one with your goal.
Edit [26July2017]:
And I cleared it !
Subscribe to:
Posts (Atom)