...

/

Whitespace in Expressions and Statements

Whitespace in Expressions and Statements

In this lesson, we'll talk about how to deal with whitespaces in Python.

Some Scenarios

See some basic Pythonic scenarios:

Press + to interact
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
ham[lower+offset : upper+offset]
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
ham[lower + offset : upper + offset]

Immediately Before the Open parenthesis

  1. Immediately before the open parenthesis that starts the argument list of a function call:
Press + to interact
educative(1)
  1. Immediately before the open parenthesis that starts an indexing or slicing:
Press + to interact
dct['key'] = lst[index]
  1. More than one space around an assignment (or other) operator to align it with another.
Press + to interact
x = 1
y = 2
long_variable = 3