Skip to content

Commit

Permalink
Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniruddh-0701 committed Oct 28, 2020
1 parent 0ff173c commit b3f8a7a
Show file tree
Hide file tree
Showing 2 changed files with 510 additions and 6 deletions.
265 changes: 263 additions & 2 deletions .ipynb_checkpoints/Modules_and_Packages-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,30 @@
"3. Builtin"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Packages:\n",
"Directory or folder containing a number of modules and subpackages.\n",
"\n",
"It contains '\\_\\_init\\_\\_.py' file which defines the modules that can be imported from the package.\n",
"\n",
"### Importing a module from package: \n",
"`import package_name.module_name` \n",
"`import package_name.module_name as custom_name`\n",
"\n",
"### Import a specific object from a module:\n",
"`from package_name.module_name import object_name`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Builtins:\n",
"\n",
"\\_\\_builins\\_\\_ module contains the list of methods and variables that are standard definitions in Python."
"\\_\\_builtins\\_\\_ module contains the list of methods and variables that are standard definitions in Python."
]
},
{
Expand Down Expand Up @@ -585,7 +602,251 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Private in modules:"
"## Private in modules:\n",
"\n",
"Objects can be restricted to usage when running as a main module. They cannot be imported when importing the complete module using ' * '.\n",
"\n",
"They start and end with double underscores, \\_\\_"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"import prime_generator as pg\n",
"\n",
"print(pg.__primeval__)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name '__primeval__' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-2-42698b27057d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mprime_generator\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m__primeval__\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mNameError\u001b[0m: name '__primeval__' is not defined"
]
}
],
"source": [
"from prime_generator import *\n",
"\n",
"print(__primeval__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## math:\n",
"This module contains list of all mathematical functions."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"__doc__\n",
"__loader__\n",
"__name__\n",
"__package__\n",
"__spec__\n",
"acos\n",
"acosh\n",
"asin\n",
"asinh\n",
"atan\n",
"atan2\n",
"atanh\n",
"ceil\n",
"comb\n",
"copysign\n",
"cos\n",
"cosh\n",
"degrees\n",
"dist\n",
"e\n",
"erf\n",
"erfc\n",
"exp\n",
"expm1\n",
"fabs\n",
"factorial\n",
"floor\n",
"fmod\n",
"frexp\n",
"fsum\n",
"gamma\n",
"gcd\n",
"hypot\n",
"inf\n",
"isclose\n",
"isfinite\n",
"isinf\n",
"isnan\n",
"isqrt\n",
"ldexp\n",
"lgamma\n",
"log\n",
"log10\n",
"log1p\n",
"log2\n",
"modf\n",
"nan\n",
"perm\n",
"pi\n",
"pow\n",
"prod\n",
"radians\n",
"remainder\n",
"sin\n",
"sinh\n",
"sqrt\n",
"tan\n",
"tanh\n",
"tau\n",
"trunc\n"
]
}
],
"source": [
"import math\n",
"\n",
"print(*dir(math), sep='\\n')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.5707963267948966\n",
"1.5707963267948966\n"
]
}
],
"source": [
"import math\n",
"\n",
"print(math.pi/2)\n",
"print(math.asin(1))\n",
"# 1.570796... = pi/2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"22\n",
"21\n"
]
}
],
"source": [
"# 21.33 ceil - 22\n",
"# 21.33 floor - 21\n",
"# 21, 21.33, 22\n",
"print(math.ceil(21.33))\n",
"print(math.floor(21.33))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8.0"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.pow(2, 3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$^5P_2$ \n",
"$^5C_2$"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.perm(5, 2) # 5P2"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.comb(5, 2)"
]
},
{
Expand Down
Loading

0 comments on commit b3f8a7a

Please sign in to comment.