python presentation 1
python presentation 1
The main reasons why we should study these topics are the following:
1. Efficient use of functions created by others
2. Proper structures when you are creating your own python solutions for problems
so when it needs to perform the tasks which it is not good at then it relies on modules and
packages. And by using help(modules) command we can get the built in modules of python
these are some of the modules
Now, let’s discuss some of the useful and frequently used built-in modules of Python.
Math Module and statistics module Some of the most popular mathematical functions that are
defined in the math module include,
Trigonometric functions,
Representation functions,
Logarithmic functions,
Angle conversion functions, etc.
In addition, two mathematical constants- pi and e are also defined in this module.
And in statics module the following popular statistical functions are defined
Mean
Median
Mode
Standard Deviation
So this about the standard libraries,modules and packages,now we will discuss about the module
search path,
To import any module we will use import function, when we use this function
The interpreter searches for the file
o In the current directory
o In the PYTHONPATH environment variable list of directories
O The directories configured as part of your Python installation
The module search path is stored in the system module sys as the sys.path variable. The
sys.path variable contains the current directory, PYTHONPATH, and the installation-
dependent default.
Now we use the dir function to check the modules present in the system ,
The dir() built-in function returns a sorted list of strings containing the names defined by a
module.
The list contains the names of all the modules, variables and functions that are defined in a
module. THIS THE simple example :
This is how we will import a module
And now we will discuss the points which are helpful in writing python codes such
that other programmers can easily understand our code.
In our beginner stages as programmers, we tend to develop habits that enable us to receive
the solution to a particular program or task in the easiest manner possible. However, it can be
questioned whether obtaining the answer in this easy fashion is the most efficient and
effective method to computing the following problem.
The second approach is to print the statement once and use a multiplier
to receive the desired output.
Image
The final approach that we will look at is to make use of a for loop for
performing this action.
Image
Hence, with effective documentation, not only do you help yourself who is
reading the code after a long time, but you also help other people who
want to read and understand your code. So, it is a good practice to input
some lines of comments explaining the purpose of the codes, especially
when publishing on a platform for others to view the code.