0 évaluation0% ont trouvé ce document utile (0 vote) 19 vues7 pagesModules, Comment & Pip
This is short notes for the python.
Copyright
© All Rights Reserved
Formats disponibles
Téléchargez aux formats PDF ou lisez en ligne sur Scribd
Chapter 2: Modules,
Comment & Pip
crn,
2.1 Modules in Python:
¢ Modules provide a way to organize your code logically.
Instead of having all your code in a single file, you can
split it into multiple modules based on their purpose
¢ For example, you might have one module for handling
input/output operations, another for mathematical
calculations, and another for data manipulation.
* When you want to use the functionality from a module,
you can import it into your current program or another
module.
¢ This allows you to access and use the functions, classes,
and variables defined within that module. By importing a
module, you can avoid writing the same code repeatedly
and instead reuse the code defined in the module.
(Ahecurious programme
o SOThree Main Types of Modules
Modules Lae fole [OC UE TT id Modules
Built-in Modules:
* These are modules that come pre-installed with Python.
They are part of the standard library and provide a wide
range of functionalities.
* Examples include modules like math for mathematical
operations, random for generating random numbers,
DateTime for working with dates and times, and os for
interacting with the operating system.
* Built-in modules are readily available for use without the
need for additional installations.
© Qpeesrcus rogram eeExternal Modules:
* These are modules that are created by third-party
developers and are not part of the standard library.
* They extend Python's capabilities by providing additional
functionalities for specific purposes. External modules can
be downloaded and installed using package managers
like pip (Python Package Index).
¢ Popular external modules include numpy for numerical
computations, pandas for data manipulation and
analysis, matplotlib for data visualization, and requests
for making HTTP requests.
User-Defined Modules:
¢ These are modules created by the Python programmers
themselves. They allow users to organize their code into
separate files and reuse functionality across multiple
programs.
¢ User-defined modules can contain functions, classes,
variables, and other code that can be imported and used
in other Python scripts or modules.
ie)2.2 Comments in Python
*« Comments in Python are used to provide explanatory
notes within the code that are not executed or interpreted
by the computer.
* They are helpful for improving code readability and for
leaving reminders or explanations for other developers
who might work with the code in the future.
In Python, comments are denoted by the hash symbol (#)
followed by the comment text.
¢ It's important to note that comments are meant for
human readers and are not executed by the Python
interpreter. Therefore, they have no impact on the
program's functionality or performance.
Types of Comments
Multi-Line Commen
Single-Line Comment1. Single-line comments:
¢ Single-line comments are used to add explanatory notes
or comments on a single line of code.
* They start with a hash symbol (#) and continue until the
end of the line.
e Anything written after the hash symbol is considered a
comment and is ignored by the Python interpreter.
Here's an example:
2. Multi-line comments:
* Multi-line comments, also known as block comments, allow
you to add comments that span multiple lines.
¢ Python does not have a built-in syntax specifically for
multi-line comments, but you can achieve this by using
triple quotes (either single or double quotes) to create a
string that is not assigned to any variable. Since it is not
used elsewhere in the code, it acts as a comment.Here's an example:
2.3 What is a pip?
¢ In simple terms, pip is a package manager for Python. It
stands for "Pip Installs Packages’ or "Pip Installs Python.”
¢ When working with Python, you may need to use external
libraries or modules that provide additional functionalities
beyond what the standard library offers. These libraries are
often developed by the Python community and are
available for anyone to use.
¢ Pip makes it easy to install, manage, and uninstall these
external libraries. It helps you find and download the
libraries you need from the Python Package Index (PyPI),
which is a repository of Python packages maintained by
the community.
With pip, you can install a package by running a simple
command in your terminal or command prompt.3. Variables, Data Types
Keywords & Operators
Chapter 3 will Be
Uploaded Tomorrow
Follow for More Notes
Qowwrious .programmer
Vous aimerez peut-être aussi