Core Programming Academy Python Notes 1: 1
PYTHON FILE STRUCTURE
• Extension for a python file is ‘py’.
For example, sort.py, math.py
• We can create a Python module just by giving ‘.py’ extension to any text
file. A Python module can contain classes, functions and statements.
From which classes and functions are optional. Statements are general
Python programming syntax.
• Classes in Python module are denoted by ‘class’ keyword. A class can
have functions and statements inside it. Again, a class may or may not
have functions in it.
• Functions in Python module are denoted using ‘def’ keyword.
• Statements can be inside or outside of the class / function body.
• General structure for a python module can be represented as:
____________________________________
Module
Classes [OPTIONAL]
Functions [OPTIONAL]
Statements
_____________________________________
Module
Class
Statements
_____________________________________
Module
Function
Statements
_____________________________________
Module
Statements
_____________________________________
Core Programming Academy – An academy by Yogeshwar Shukla
Mobile: +91 956 154 7043
Email: coreprogrammingacademy@gmail.com
Core Programming Academy Python Notes 1: 2
• Different Python packages can also be included in a module using
‘import’ statement. Python packages are nothing but another python
modules providing some functionality. For example, if we write a python
module ‘MyMath.py’ having addition, subtraction etc. functions, other
programmers can use our module as package in their program just by
writing –
import MyMath
and can use our functionality.
• General Syntax of a Python program:
import <PACKAGE_NAME>
class <CLASS_NAME>:
def <FUNCTION_NAME>:
BLOCK OF STATEMENTS
.
.
.
.
def <FUNCTION_NAME> (ARGUMENT_LIST):
BLOCK OF STATEMENTS
.
.
.
<FUNCTION_NAME> (ARGUMENT_LIST)
Core Programming Academy – An academy by Yogeshwar Shukla
Mobile: +91 956 154 7043
Email: coreprogrammingacademy@gmail.com