Topic 01 Introduction To Python
Topic 01 Introduction To Python
introduction
to python
(Indention, Comments, Variables)
SAMPLE CODE:
INDENTATION
SAMPLE CODE:
INDENTATION
SAMPLE CODE:
INDENTATION
You have to use the same number of spaces in the same block of
code, otherwise Python will give you an error:
SAMPLE CODE:
comments
SAMPLE CODE:
comments
Comments can be placed at the end of a line, and Python will ignore
the rest of the line:
SAMPLE CODE:
comments
A comment does not have to be text that explains the code, it can
also be used to prevent Python from executing code:
SAMPLE CODE:
comments
SAMPLE CODE:
comments
SAMPLE CODE:
comments
SAMPLE CODE:
VARIABLES
Variables do not need to be declared with any particular type, and
can even change type after they have been set.
SAMPLE CODE:
VARIABLE NAMES
SAMPLE CODE:
Variable names with more than one word can be difficult to read.
There are several techniques you can use to make them more
readable:
VARIABLE NAMES
CAMEL CASE
PASCAL CASE
SNAKE CASE
SAMPLE CODE:
SAMPLE CODE:
ASSIGN MULTIPLE VALUES
Unpack a Collection
If you have a collection of values in a list, tuple etc. Python allows
you to extract the values into variables. This is called unpacking.
ASSIGN MULTIPLE VALUES
SAMPLE CODE:
OUTPUT VARIABLES
The Python print() function is often used to output variables.
SAMPLE CODE:
OUTPUT VARIABLES
In the print() function, you output multiple variables, separated
by a comma:
SAMPLE CODE:
OUTPUT VARIABLES
You can also use the + operator to output multiple variables:
SAMPLE CODE:
OUTPUT VARIABLES
Notice the space character after "Python " and "is ", without
them the result would be "Pythonisawesome".
OUTPUT VARIABLES
SAMPLE CODE:
OUTPUT VARIABLES
In the print() function, when you try to combine a string and a
number with the + operator, Python will give you an error:
SAMPLE CODE:
OUTPUT VARIABLES