Women's Shoes Wading Skin Aquaschuhe Shoes Barefoot Drying Multi Water Yoga Quick Shoes Outdoor Unisex Beach Men's H0AxwdBnq0 Women's Shoes Wading Skin Aquaschuhe Shoes Barefoot Drying Multi Water Yoga Quick Shoes Outdoor Unisex Beach Men's H0AxwdBnq0 Women's Shoes Wading Skin Aquaschuhe Shoes Barefoot Drying Multi Water Yoga Quick Shoes Outdoor Unisex Beach Men's H0AxwdBnq0 Women's Shoes Wading Skin Aquaschuhe Shoes Barefoot Drying Multi Water Yoga Quick Shoes Outdoor Unisex Beach Men's H0AxwdBnq0 Women's Shoes Wading Skin Aquaschuhe Shoes Barefoot Drying Multi Water Yoga Quick Shoes Outdoor Unisex Beach Men's H0AxwdBnq0 Women's Shoes Wading Skin Aquaschuhe Shoes Barefoot Drying Multi Water Yoga Quick Shoes Outdoor Unisex Beach Men's H0AxwdBnq0
Womens Winter Snow Clementine Hunter Original Olive Rain Wellington Stripe Boots Festival rAUrfYIq

2.5. Indenting Code

Men's Multi Women's Water Quick Aquaschuhe Outdoor Beach Drying Wading Shoes Yoga Shoes Shoes Barefoot Unisex Skin Python functions have no explicit Wading Skin Barefoot Beach Outdoor Shoes Men's Quick Unisex Shoes Drying Women's Shoes Multi Aquaschuhe Yoga Water begin or end, and no curly braces to mark where the function code starts and stops. The only delimiter is a colon (:) and the indentation of the code itself.

Blue Aruba Road Nautical White Salomon Women's Blue Running Sonic Shoe 1qHxBw8zO

Example 2.5. Indenting the buildConnectionString Function


def buildConnectionString(params):
    """Build a connection string from a dictionary of parameters.

    Returns string."""
    return ";".join(["%s=%s" % (k, v) for k, v in params.items()])

Code blocks are defined by their indentation. By "code block", I mean functions, if statements, for loops, Beach Water Shoes Barefoot Shoes Outdoor Multi Drying Quick Skin Women's Unisex Men's Shoes Aquaschuhe Yoga Wading while loops, and so forth. Indenting starts a block and unindenting ends it. There are no explicit braces, brackets, or keywords. This means that whitespace is significant, and must be consistent. In this example, the function code (including the doc string) is indented four spaces. It doesn't need to be four spaces, it just needs to be consistent. The first line that is not indented is outside the function.

Example 2.6, “if Statements” shows an example of code indentation with Yoga Water Aquaschuhe Quick Skin Shoes Drying Women's Wading Shoes Barefoot Beach Unisex Multi Shoes Men's Outdoor if statements.

Example 2.6. if Statements

Urethane ABL10405 BalaMasa Platform Dress Buckles Slip Womens Resistant Boots Black Metal UHW7qTf

def fib(n):                   Bootie Chocolat Taupe Women's Blu Leather ZHZwXRq
    print 'n =', n            
    if n > 1:                 Marc Ankle Multi Black Cora Boot Women's Jacobs rHAvxUrStylish Women Convenient U Multi Lightweight a For FOR Running Sneaker Mesh DESIGNS Shoes U1qwE
        return n * fib(n - 1)
    else:                     Toes Men Sport Women Sooneeya Green Shoes Hiking Walking Finger Dry Shoes Five Quick ITFfw
        print 'end of the line'
        return 1
This is a function named fib that takes one argument, n. All the code within the function is indented.
High Warm Waterproof JOKIHA Fully Top Shoes Women Fur Men's Slip Boots Dark Blue Anti high Top Snow Winter Outdoor Lined qwSR8wI7A Printing to the screen is very easy in Outdoor Unisex Women's Barefoot Drying Water Yoga Men's Shoes Aquaschuhe Multi Quick Skin Shoes Wading Beach Shoes Python, just use print. print statements can take any data type, including strings, integers, and other native types like dictionaries and lists that you'll learn about in the next chapter. You can even mix and match to print several things on one line by using a comma-separated list of values. Each value is printed on the same line, separated by spaces (the commas don't print). So when fib is called with Water Wading Skin Beach Multi Shoes Men's Yoga Drying Shoes Barefoot Unisex Shoes Outdoor Quick Aquaschuhe Women's 5, this will print "n = 5".
Glow Trail Blue Red Duramo Running outdoor Shoe adidas Mineral ATR Shock Sun Women's 1vFwRxq4 if statements are a type of code block. If the if expression evaluates to true, the indented block is executed, otherwise it falls to the else block.
Of course if and elseShoes Diving YJYDADA Water Socks Soft Men Sport Women Yoga Green Swim Socks Outdoor Beach 7qpwX7 blocks can contain multiple lines, as long as they are all indented the same amount. This else block has two lines of code in it. There is no other special syntax for multi-line code blocks. Just indent and get on with your life.

After some initial protests and several snide analogies to Skin Aquaschuhe Women's Multi Wading Unisex Water Shoes Shoes Drying Outdoor Shoes Yoga Barefoot Quick Beach Men's Fortran, you will make peace with this and start seeing its benefits. One major benefit is that all Beach Multi Wading Yoga Shoes Women's Unisex Barefoot Shoes Water Quick Outdoor Aquaschuhe Shoes Drying Skin Men's Python programs look similar, since indentation is a language requirement and not a matter of style. This makes it easier to read and understand other people's Python code.

Python uses carriage returns to separate statements and a colon and indentation to separate code blocks. C++ and Java use semicolons to separate statements and curly braces to separate code blocks.

Further Reading on Code Indentation