Learning the Language - Becoming a Parselmouth

By Ryan Wiles

Language Overview

Insert A high-level overview of the Python Language

Discuss the Philosophy and what it means to write pythonic code

Basic Syntax, Semantics, and Conventions

Whitespace & Flow Control

Indentation

Flow control Defines the Control Blocks

Spaces vs Tabs

https://www.python.org/dev/peps/pep-0008/#indentation Use spaces, not tabs 4 spaces per indention

Alignment: Hanging Indents:

https://www.python.org/dev/peps/pep-0008/#indentation

Aligned with opening delimiter
Should always add a level over the immediately following indentation level

In Expressions and Statements

https://www.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements

Trailing Commas

https://www.python.org/dev/peps/pep-0008/#when-to-use-trailing-commas

Expressions

A single expression per line is preferred, the default expression terminator is the new line character

Multiple expressions are supported using semicolons as the separator

An expression can span multiple lines using the following mechanisms:

Explicit Line Continuation

A backslash ‘' immediately before the new line character continues the expression to the next line.

This style is generally frowned upon.

Examples of Exceptions to the Rule:

  Long statements with multiple "with" statements
  Assert statements

Implicit Line Continuation

  For statements containing '(', '{', or '[', the expression will continue across new lines until all matching
  closing parantheses, braces, or brackets have been processed.
  Aligning the closing parantheses, braces, and brackets

Line Length

Non-Comment (i.e. Code) lines should not exceed 79 characters Comment & Docstring lines should be limited to 72 characters

Naming Conventions

https://www.python.org/dev/peps/pep-0008/#naming-conventions

https://www.python.org/dev/peps/pep-0008/#prescriptive-naming-conventions

http://www.cse.msu.edu/~cse231/General/NamingConventions.pdf

Variable Naming Conventions

Constants

Module/File Naming Conventions

https://www.python.org/dev/peps/pep-0008/#package-and-module-names

“Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.”

Package Naming Conventions

https://www.python.org/dev/peps/pep-0008/#package-and-module-names

“Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.”

Class Naming Conventions

Keywords

Imports

Modules

Module is the name that python gives to https://docs.python.org/3/tutorial/modules.html

Default Global Variables

__name__: This is automatically set to the module’s name.

Module Level Dunder Names

https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names

Structure:

Packages

Structure:

Commenting Your Code

https://www.python.org/dev/peps/pep-0008/#comments

Comments:

Docstrings:

Brief Introduction to Objects in Python

Comprehensions

Python syntax and semantics

Lexical Closures

Python syntax and semantics

Lambda Expressions:

Generators

Python syntax and semantics

Lazy Evaluation

Generator Expressions

Trampolining & Generators: Overcoming the Stack and Simulating Tail Call Recursion

Back to the Bunnies

Example of Fibonacci using Trapolining & Generators

Variables

Variable Annotations

Declaration

Usage

Data Types

Literals

Strings

Quoting (Single Quote vs Double Quote)

Numbers

Built-in Data Structures

Lists

Tuples

Sets

Dictionaries

Dictionary & Set Comprehensions

Objects

Object Oriented Programming in Python 3

With Statements

Object Properties

Object Descriptors

Class and Static Methods

Inheritence

Basic Operations

Arithmetic Operators

String Concatination

Type Conversion

Boolean Operations

Conditionals

Loops

Functions

Function Annotations: Decorators:

Classes

Methods

Surrounded by one blank line

Exceptions & Error Handling

If-Blocks vs Exceptions

Logging

Writing Pythonic Code

Secure Programming in Python

References

© 2018 Ryan Wiles