Module 1 Fundamentals
Module 1 Fundamentals
Fundamentals of n
“” #
Python
()
Agenda
( ) #
Python uses
● Single-line indentation to ● Empty
● Multi-line indicate a block of ● Simple
● Docstring code. ● Compound
COMMENT
wHY DO WE USE
COMMENTS#
Pytho
n
Computer ignores any text
“‘’ # written after the hash.
”
# # ‘‘‘’’
’
Single-line Multi-line Doc string
COMMENT COMMENT
COMMENT
Single-line
comment
# ●
●
Starts with a hash symbol (#)
#
Can write comments of multiple lines using
hash at the beginning of each line.
Example
# THIS IS A MULTILINE
# COMMENT IN PYTHON
# USING THE SINGLE LINE
# COMMENT CONSECUTIVELY
COMMENT
Doc string
‘‘‘’’’
● Comment spans within multiple lines.
● Ignores everything in quotation marks.
“““””” ●
●
Written using 3 signal or 3 double quotes.
This is called Doc strings.
Example
“““You can write docstring like this”””
‘‘‘You can also write docstring like this’’’
COMMENT
When to use
comment?
‘‘‘’’ ●
●
Projects you work on will be inherited by other
people
Comments make it easier for you to read your
’ ●
code!
Make sure the comment is short and relevant to
the code
LMS Assignment
Indentation
Importance of INDENTATION
INDENTATIOn ERROR
Indentation
wHAT IS
INDENTATION?
● Indentation refers to the spaces at the
INDENTATION
beginning of a code line. ERROR
● Whitespace is used for indentation in
Python.
● Python uses indentation to highlight the
blocks of code.
● All statements with the same distance to
the right belong to the same block of
code.
Indentation
Look at the
meme
All statements with the same distance to
the right belong to the same block of
code.
If a block has to be more deeply nested,
it is simply indented further to the right.
Indentation
Example
Program
Indentation
Example
For
statement
If statement
LMS Assignment
Primary Data Type
.py .txt
Numbers Strings
Data Type
True/False
Boolean
Numbers
+ For string
What are
statements?
Types of
Simple Statement Complex Statement
statements
● Comprised in a single line. ● A collection of statements
working together.
● Never affect the flow of
program. ● May affect the flow of
Empty Statement program.
● Example:
● Example:
a=10, break, return, break,
pass if, elif, else, for, while, try, etc.
Values and variable
What is a
variable?
height =1.79
weight = 68.7
bmi = weight / height * height
print(bmi)
LMS Assignment
Identifiers
What are
identifiers?
Assign multiple
Simple Assignment values to multiple
variables
Example Example
a=100 a, b = 100, 200
print(a) print(a)
100 100
print(b)
200
Types of Assignments
Categories of keywords
Built-in
Description Code Output
Function
Returns absolute value of a
abs() number
abs(-11) Answer: 11
Raises a number to a
pow() power
pow(10, 2) Answer: 100