From the course: Network Automation Quick Start

PEP 8: Python style guide

- [Instructor] If you wanna get some recommendations with regards to spacing and other best practices, do a search for Python PEP 8 in Google and this gives you information about how you should be writing code in Python. This is the style guide for Python code and they talk about indentation, and we're told to use four spaces per indentation level. If you want any recommendations about how you should write code, have a look at the style guide. One of the questions that often comes up is string quotes. Should you be using single or double quotes? In this PEP guide, we're told that single and double quotes are treated the same. The PEP doesn't make a recommendation for this. You should simply pick a rule and stick to it. In other words, either use single quotes or double quoted strings. When a string contains single or double quote characters, however, use the other one to avoid backslashes to improve readability. In other words, in this example, with my Python range, I'm using single quote characters. If you actually wanna quote the word hello as if you're quoting someone saying something, like this, then use the other quotation within your string. Python3, python3range, notice we see hello like this. If, however, I did this, we would have a problem in our code. If I try to run that, we're getting an error. If I wanted to keep on using single quotes, I'd have to do this to indicate that it's actually what I want. That works or I could do what PEP 8 says and use double quotation marks to indicate that this hello is actually within a quote. Run that again and that once again works. The moral of the story is be consistent.

Contents