Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements & Comments & Mathematics
by James • July 7, 2012 • Project Weekend
Whitespace and Statements
Now that you’re getting the hang of variables, values, and assignment (think of them like the subjects, objects, and verbs of English sentences), let’s take a look at whitespace and statements: the sentences of our new Python language.
Ok, so I have got to level 2 here, as you can see, and the column on the left has some wise words for us:
You can think of a Python statement as being similar to a sentence in English: it’s the smallest unit of the language that makes sense by itself. Just like “I,” “like,” and “Spam” aren’t statements by themselves, but “I like Spam” is, variables and data types aren’t statements in Python, but theyare the building blocks that form them.
To continue the sentence analogy, it’s clear that we also need a kind of punctuation to make it obvious where one statement ends and another begins. If you’re familiar with JavaScript, you know that statements end with a semicolon (
;). In Python, statements are separated bywhitespace. Just like you can’t toss around semicolons wherever you want in JS, you can’t throw whitespace around in Python.This may take some getting used to, especially if you’re coming from a programming language where whitespace doesn’t matter.
Comments
Written by Eric Weinstein
You may have noticed the instructions in the editor that begin with a
#(pound or hash) symbol. These lines of code are calledcomments, and they aren’t read by the interpreter—they don’t affect the code at all. They’re plain English comments written by the programmer to provide instructions or explain how a particular part of the program works.Since this improves the readability of your code tremendously (and will help you debug programs more quickly, since you’ll be able to tell at a glance what each part of the program is supposed to do), we encourage you to comment on your code whenever its purpose isn’t immediately obvious.
We aren’t in Kansas anymore fellas, here we have a bit of a challenge.. just press run!
Math Operations
Written by Eric Weinstein











