Login
📚 Python for Introductory Statistics
Chapters ▾

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

  1. Arithmetic Operators: + (add), - (subtract), * (multiply), / (divide), ** (exponent). (e.g. 700*20 see Arithmetic Operators)
  2. Assignment operator = (e.g. x = 100)
  3. Comments: comment start with # and lasts to end-of-line. (e.g. # this is a comment see Comments)
  4. Strings: string (text data) is declared by either single or double quotes. (e.g. x = 'red')
  5. Variable: A variable is created via initial assignments and can hold integer, float, string etc. (e.g. y = 10.5 see Variables)
  6. Data Types: int (integers), float (decimals), str (string), bool (True or False) (e.g. y = 5 y is integer data type int)
  7. 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.