Flow_0bngcu2 # Readability The creator of Python, Guido van Rossum, said “Code is read much more often than it’s written.” It is worth taking the time to create code that is easy to understand. For this reason we recommend following a popular standard called [PEP8](https://realpython.com/python-pep8/) Here are some highlights from the standard... ## Variables ### Formatting: being consistent in the naming of your variables makes them far easier to remember. If you always use lower case and separate words with underscores, you don't have to try and remember the formatting, you just have to remember what it is called. If everyone follows this standard, then you can remember their variables easier as well ... * my_name (GOOD) * MyName (NO) * myname (NO) ### Use Thoughtful names. Avoid names that don't have meaning, or are cryptic. Try to use names that are descriptive and concise. * first_name = "Abraham" (GOOD) * x = "Abraham Lincoln" (AVOID) * fn = "Abraham" (AVOID) ## Whitespace * Use blank lines, sparingly, to show clear steps A little white space can make your code more readable. So can comments. * "Sparse is better than dense" -- Zen of Python. Place spaces around operators and boolean operations most of the time. Though it can be good to break this rule when there are multiple expressions of different priority. Take the following example, where the second line is harder to read than the first. ```python if x < 5: # GOOD if x>5 and x<10 : # GOOD if x > 5 and x < 10: # NOT AS GOOD ``` ## Use Comments Sparingly A few carefully chosen words can help *IF it isn't apparent already.* Good variable names and well written code come first. Then add additional comments only if the information is not already apparent in the code. ## Closing Brackets and braces We work with dictionaries a lot. So we recommend closing your braces and brackets with the first line to make it easy to tell when the dictionary definition is complete. For example: ```python children = { "Robert", "Edward" "Tad", "Willie" } ``` # “Simple is better than complex.” * Don't compare booleans, it's not necessary ```python is_bigger = 6 > 5 if is_bigger: # GOOD if is_bigger == True: # AVOID ``` * "is not" is easier to read: ```python if not x is None: # AVOID if x is not None: # GOOD ``` Flow_0ggy7w4 Flow_1s0vaon Flow_0x52gsc {} { "age": 54, "height": 1.93, "children": [ "Robert", "Edward", "Tad", "Willie" ], "is_married": true, "my_age": 55, "cabinet": { "Secretary of State": { "name": "William H. Seward", "age": 60, "children": [ "William Jr.", "Frederick", "Augustus", "Anna" ] } } } Flow_0bngcu2 Flow_0ggy7w4 # Adding function def add_one(input): return input + 1 # Creating Variables age = 51 # This is an integer height = 1.93 # This is a float or "floating point number" children = ['Robert', 'Edward', 'Tad', 'Willie'] # This is a list is_married = True # This is a boolean # Updating Variables Age = 50 # Variables are case sensitive, this is a new variable. age = 54 # This updates the age variable. # Referencing variables my_age = age # my_age is now set to 54 my_age = add_one(my_age) # Deleting variables del(Age) # The age variable no longer exists. You will get an error if you try to use it. # This is a dictionary, and you will use a lot of them... cabinet = { "Secretary of State": "William H. Seward", "Secretary of the Treasury": "Salmon P. Chase", "Secretary of War": "Edwin M. Stanton", "Attorney General": "Edward Bates" } # Dictionaries can be deeply nested and contain any type of variable cabinet = { "Secretary of State": { "name": "William H. Seward", "age": 60, "children": ['William Jr.', 'Frederick', 'Augustus', 'Anna'] } } Flow_1s0vaon Flow_0x52gsc