Python

Prerequisites

None (No prior knowledge of programming required)

TOOLS

Install the Python (Interpreter) following before proceeding with the tutorial

Note that for the last option, you may not be able to use 'python as a calculator' feature

introduction

Python is a high level, dynamic language invented by Guido Van Rossum in early 1990s. It is an interpreted language, where the first phase is to compiler the Python source code (.py) to bytecode (.pyc), which is then run by the Python Virtual Machine. [More on this later]

starting up

Run the Python program (Interpreter) that you downloaded


Hello World

As is the customary, the first program to write in any langusage is the one that prints the following characters -  "Hello World" - on to the console/terminal (your screen).


String methods

Strings are immutable => assignment is not allowed

email = "superman@gmail.com"

email[0] = 'd' - NOT OK

email = "batman@gmail.com" - OK, since new string is assigned to the variable email

Find a substring

email.index("@")

email.index("gmail")

email.index("yahoo") - ERROR

instead use "in" to avoid error

"yahoo" in email => False


.lower() and .upper()

.strip(), .lstrip(), .rstrip()

.count()

.endwith()

.isnumeric()

int(string)

+ => .join

.split()

String - sequence of chars; immutable

Lists - sequence of elements of any type; mutable []

Tuple - elements of any type; immutable ()