In other text editors, pressing the tab key might insert a tab character (a By default, Spyder will insert the appropriate number ofĪSCII space characters to get the text cursor to the next level of In an Spyder Editor window, pressing the tab key will cause Spyder to increase the
It provides text editor features like code highlighting and automatic We will use Spyder extensively in this course when we write programs, since
Spyder is a software program that makes it easier to write and run PythonĬode. You must use the correct indentation to create code that is syntactically correct. Python uses indentation to manage the visiblity and scope of statements in your code. Letters with underscores separating words “constants” in other languages like Java) should be written in all capital
function names (and method names) should be imperative verb phrases.Lowercase, with multiple words distinguished by a single underscore ( _) attribute and local variable names should be noun phrases, written in.Strings, then don’t use key for an integer). Hand, similar names for very different things (example: if keys is a list of Names for different things (e.g., index, indx, index2), or, on the other Increment_event_count() rather than incevcnt()). (i.e., a for loop counter could be called i) and longer names for biggerĬontexts (examples to follow). Whenever possible, write short, obvious names for very local contexts As part of program documentation, names mustĬlearly indicate both the kind of thing being named and its role in the Variable and Function NamesĬhoose your names carefully. """Īnother point to note: PEP 257 states that functionĭocstrings should be a phrase ending with a period that describes theĮffect of the function as a command, rather than describing it (see The docstring should begin on the line with the openingĭef replace ( secret_word, display_word, letter ): """Return a list of characters that results from taking the existing display word list and revealing any and all occurrences of the specified letter, as dictated by secret_word. Use the triple-double quotation marks ( """) to start and end aĭocstring. Surrounding comments, since they can be reviewed using Python’s help()įunction, among other uses. They are simple strings that are better than py file), function (after the def line), or class Indent the comments to line up with the code.īefore every control structure (e.g., if/else statement, loop), explain why thisĬontrol structure is necessary/what it is doing.ĭocumentation strings (or docstrings) can be attached to any module Program, give the purpose of that section. When it helps to understand your code, before each major section of the Non-significant variables (not requiring explanation) would include temporary The use of the variable, and when useful, the units (e.g., feet or inches). In particular, please observe the followingįor each significant variable declaration, give a brief comment stating The grader that you grasp the what, how and why of your code (as opposed The case of a program submitted for this course, they also serve to convince
You to understand it if you need to rework your code at some later point. CommentsĬomments should help the reader of your code to understand it. # File: hello_world.py # Author: John Magee # Description: Our first Python program, in which we demonstrate # writing output to the console window.