[go: up one dir, main page]

0% found this document useful (0 votes)
23 views2 pages

2 PythonFIleStructure

The document outlines the structure of Python files, emphasizing that they use the '.py' extension and can contain modules, classes, functions, and statements. It explains how to define classes and functions using the 'class' and 'def' keywords, respectively, and mentions the use of 'import' statements to include other Python packages. A general syntax for a Python program is also provided to illustrate the organization of code within a module.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

2 PythonFIleStructure

The document outlines the structure of Python files, emphasizing that they use the '.py' extension and can contain modules, classes, functions, and statements. It explains how to define classes and functions using the 'class' and 'def' keywords, respectively, and mentions the use of 'import' statements to include other Python packages. A general syntax for a Python program is also provided to illustrate the organization of code within a module.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like