Python rules

Quotes and Double quotes


Python is a case sensitive programming language

One of the first caveats programmers encounter when learning Python is the fact that there are no braces to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced.

If any of the code below doesn't work the first thing is to check the indentation (i.e use a space) for terms such as "print" which are below and if/loop/logic

Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue

A hash sign (#) that is not inside a string literal begins a comment

The semicolon ( ; ) allows multiple statements on the single line

To run a python program python or chmod 755 and then ./

# are for comments
>>> 'doesn\'t' # use \' to escape the single quote...
"doesn't" # or use double quotes
if you don’t want characters prefaced by \ to be interpreted as special characters, you can use raw strings by adding an r before the first quote:

Any of the below starting with >>> is using the python command line.

Quotes and Double quotes

Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string.(for more on triple quote see Triple quotes

In some cases, when you need to include really long strings instead of terminating each line with \n\, i.e

hello = """




Semi colons are very rarely used, colons are used a bit more frequetley with indentations (while,if,else,elif,defining functions)

taken from

The colon is required primarily to enhance readability (one of the results of the experimental ABC language). Consider this:

if a == b
print a


if a == b:
print a

Notice how the second one is slightly easier to read. Notice further how a colon sets off the example in this FAQ answer; it’s a standard usage in English.

Another minor reason is that the colon makes it easier for editors with syntax highlighting; they can look for colons to decide when indentation needs to be increased instead of having to do a more elaborate parsing of the program text.