3. Python Syntax
"The syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be correctly structured statements or expressions in that language." Wikipedia
Syntax Summary
- Arithmetic Operators:
+(add),-(subtract),*(multiply),/(divide),**(exponent). (e.g. 700*20 see Arithmetic Operators) - Assignment operator
=(e.g.x = 100) - Comments: comment start with # and lasts to end-of-line. (e.g.
# this is a commentsee Comments) - Strings: string (text data) is declared by either single or double quotes. (e.g.
x = 'red') - Variable: A variable is created via initial assignments and can hold integer, float, string etc. (e.g.
y = 10.5see Variables) - Data Types: int (integers), float (decimals), str (string), bool (True or False) (e.g.
y = 5y is integer data typeint) -
Statements: Statements start at the left end (column one) of a line and end with a newline.
Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.