{"id":2597,"date":"2022-02-03T12:45:37","date_gmt":"2022-02-03T07:15:37","guid":{"rendered":"https:\/\/cbsepython.in\/?p=2597"},"modified":"2026-01-05T13:50:14","modified_gmt":"2026-01-05T08:20:14","slug":"introduction-to-python-module-class-11-computer-science","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/introduction-to-python-module-class-11-computer-science\/","title":{"rendered":"Introduction to Python Module Class 11 Notes Computer Science"},"content":{"rendered":"<h1><span style=\"color: #000000;\">Introduction to Python Module Class 11 Computer Science<\/span><\/h1>\n<p><strong data-start=\"97\" data-end=\"115\">Python modules<\/strong> are a key concept in the <strong data-start=\"141\" data-end=\"177\">Class 11 Computer Science (CBSE)<\/strong> syllabus and are commonly asked in board exams and practical assessments. A Python module is a program file that contains functions, variables, or classes which can be reused in other programs using the <code data-start=\"381\" data-end=\"389\" data-is-only-node=\"\">import<\/code> statement. Learning modules helps students write <strong data-start=\"439\" data-end=\"482\">organized, efficient, and reusable code<\/strong>, making it easier to manage large Python programs as per <strong data-start=\"540\" data-end=\"560\">NCERT guidelines<\/strong>.<\/p>\n<h3><span style=\"color: #000000;\">What is module in Python?<\/span><\/h3>\n<p><span style=\"color: #000000;\">Modules are\u00a0<b>simply files with the \u201c.<\/b>\u00a0<b>py\u201d extension containing Python code<\/b> that can be imported inside another Python Program. A\u00a0<em>module<\/em> can contain executable statements as well as function definitions. A module allows you to logically organise your python code. <\/span><\/p>\n<p>&nbsp;<\/p>\n<h3 class=\"d9FyLd\"><span style=\"color: #000000;\">User-Defined Modules in Python<\/span><\/h3>\n<p><span class=\"hgKElc\" style=\"color: #000000;\">You can create your own functions and classes, put them inside modules and voila! You can now include hundreds of lines of code into any program just by writing a simple import statement. To create a module, just put the code inside a . py file.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Creating a Module in Python:<\/span><\/h3>\n<p><span style=\"color: #000000;\">In Python , the modules or User-Defined functions are created with def keyword. The general syntax is:<\/span><\/p>\n<p>&nbsp;<\/p>\n<blockquote><p><strong><span style=\"color: #000000;\">def module_name\/function_name():<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #000000;\">python program statements<\/span><\/strong><\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<p><strong><span style=\"color: #000000;\"># Program to create a module in Python.<\/span><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def sum():\r\n    a=int(input(\"Enter first number\"))\r\n    b=int(input(\"Enter second number\"))\r\n    result=a+b\r\n    print(\"sum of %d and %d is %d\"%(a,b,result))\r\n<\/pre>\n<p><span style=\"color: #000000;\">Now I am saving the above python code as sum_module.py.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Importing Python Module in Same Program:<\/span><\/h3>\n<p><span style=\"color: #000000;\">Now we will import the above created module.<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre>&gt;&gt;&gt; import sum_module\r\n&gt;&gt;&gt; sum_module.sum()\r\nEnter first number45\r\nEnter second number34\r\nsum of 45 and 34 is 79\r\n&gt;&gt;&gt;<\/pre>\n<h3><\/h3>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-2605 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/pyhon_module-1-e1643785506466.png\" alt=\"\" width=\"377\" height=\"189\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/pyhon_module-1-e1643785506466.png 377w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/pyhon_module-1-e1643785506466-300x150.png 300w\" sizes=\"(max-width: 377px) 100vw, 377px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Importing Python Module in another Program<\/span><\/h3>\n<p><span style=\"color: #000000;\">Let we create a simple calculator module\/function with three basic functions add, multiplication and division (+,* ,\/). We will save the python file as <em><strong>calculator.py<\/strong><\/em>.<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># creating module\/function with three airthmetic operations (+,* and \/)\r\ndef sum(a,b):\r\n    result= a+b\r\n    return result\r\ndef mul(a,b):\r\n    result= a*b\r\n    return result\r\ndef div(a,b):\r\n    result= a\/b\r\n    return result\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">Now we will create an another python program named mathclc.py , from where we access the functions of above program calculator.py.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># importing calculator module\r\nimport calculator \r\na=int(input(\"Enter first number\"))\r\nb=int(input(\"Enter second number\"))\r\nprint (\"sum of entered numbers\",calculator.sum(a,b))\r\nprint (\"multiplication of entered numbers\",calculator.mul(a,b))\r\nprint (\"division of entered numbers\",calculator.div(a,b))\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<pre><span style=\"color: #000000;\">Enter first number10<\/span>\r\n<span style=\"color: #000000;\">Enter second number2<\/span>\r\n<span style=\"color: #000000;\">('sum of entered numbers', 12)<\/span>\r\n<span style=\"color: #000000;\">('multiplication of entered numbers', 20)<\/span>\r\n<span style=\"color: #000000;\">('division of entered numbers', 5)<\/span>\r\n<span style=\"color: #000000;\">&gt;&gt;&gt;<\/span><\/pre>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2608 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_clc-e1643785573763.png\" alt=\"\" width=\"543\" height=\"161\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_clc-e1643785573763.png 543w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_clc-e1643785573763-300x89.png 300w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_clc-e1643785573763-400x119.png 400w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>The from import Statement<\/h2>\n<p>With this method we can import some specific function definitions from a module without importing the whole module.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<blockquote><p><strong>from module_name import function_name<\/strong><\/p><\/blockquote>\n<p>For better understanding we will implement this method in above created module <strong>calculator.py<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&gt;&gt;&gt; from calculator import sum\r\n&gt;&gt;&gt; sum(10,12)\r\n22\r\n&gt;&gt;&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2611 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/from-import.png\" alt=\"\" width=\"462\" height=\"137\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/from-import.png 462w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/from-import-300x89.png 300w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/from-import-400x119.png 400w\" sizes=\"(max-width: 462px) 100vw, 462px\" \/><\/p>\n<h3><\/h3>\n<h3><span style=\"color: #000000;\">The from module import * Statement<\/span><\/h3>\n<p><span style=\"color: #000000;\">In this method we import all the functions from a module into the current program. In this method (*) means to import all objects into the calling program.\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\"><strong>Syntax:<\/strong><\/span><\/p>\n<blockquote><p><span style=\"color: #000000;\"><strong>from module_name import *<\/strong><\/span><\/p><\/blockquote>\n<p><span style=\"color: #000000;\">In previous programs we created <strong>calculator.py <\/strong>module<strong>. <\/strong>Now we will create another module <strong>area.py<\/strong> to calculate area of rectangle and will import these two modules in another program named <strong>test.py<\/strong>.<\/span><\/p>\n<p><strong><span style=\"color: #000000;\"># Python function\/ module to calculate area of rectangle area.py<\/span><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># module\/function to calculate area of rectangle\r\ndef react_area(l,w):\r\n    result=(l*w)\r\n    return result\r\n    \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"># Python module <strong>test.py<\/strong> in which we import above modules <strong>calculator.py <\/strong>and<strong>area.py.<\/strong><\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from calculator import *\r\nfrom area import *\r\nprint(\"area of rectangle\",react_area(5,3))\r\nprint(\"sum of entered numbers is\",sum(5,3))\r\n<\/pre>\n<p>&nbsp;<\/p>\n<pre><span style=\"color: #000000;\">Output:<\/span>\r\n\r\n<span style=\"color: #000000;\">('area of rectangle', 15)<\/span>\r\n<span style=\"color: #000000;\">('sum of entered numbers is', 8)<\/span>\r\n<span style=\"color: #000000;\">&gt;&gt;&gt;<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #000000;\">Built in Modules\/ Standard Library in Python<\/span><\/h3>\n<p><span style=\"color: #000000;\">A library is just a module that contains some useful definitions. Python has a large variety of standard library modules.\u00a0 \u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">Some of them are math module, random module, datetime module and statistics module etc.\u00a0<\/span><\/p>\n<p><strong><span style=\"color: #000000;\">In this section we will only cover math module.\u00a0<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\">math Module:<\/span><\/h2>\n<p><span style=\"color: #000000;\">Python has a math module that provides most of the mathematical and trigonometric functions. To use math module you just have to put a line import math at the top of your python code.\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">How to use:\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">Syntax:<\/span><\/p>\n<p><span style=\"color: #000000;\">import math<\/span><\/p>\n<p><span style=\"color: #000000;\">print math.function_name(variable)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">math module has the following functions.\u00a0\u00a0<\/span><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">Function<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Description\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">pi<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Mathematical constant, the ratio of circumference of a circle to it&#8217;s diameter (3.14159&#8230;)<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">e<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">mathematical constant e (2.71828&#8230;)<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">sqrt(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the square root of x<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">ceil(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the smallest integer greater than or equal to x<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">floor(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the largest integer less than or equal to x<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">pow(x,y)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns x raised to the power y<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">fabs(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the absolute value of x<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">sin(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the sine of x<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">cos(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the cosine of x<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 17.6364%;\"><span style=\"color: #000000;\">tan(x)<\/span><\/td>\n<td style=\"width: 82.3636%;\"><span style=\"color: #000000;\">Returns the tangent of x<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\">Implementation of math module<\/span><\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import math\r\nprint(math.pi)\r\nprint(math.e)\r\nprint(math.sqrt(25))\r\nprint(math.ceil(5))\r\nprint(math.floor(8))\r\nprint(math.pow(4,3))\r\nprint(math.fabs(3))\r\nprint(math.sin(30))\r\nprint(math.cos(60))\r\nprint(math.tan(45))\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Output:<\/strong><\/p>\n<pre><span style=\"color: #000000;\">3.14159265359<\/span>\r\n<span style=\"color: #000000;\">2.71828182846<\/span>\r\n<span style=\"color: #000000;\">5.0<\/span>\r\n<span style=\"color: #000000;\">5.0<\/span>\r\n<span style=\"color: #000000;\">8.0<\/span>\r\n<span style=\"color: #000000;\">64.0<\/span>\r\n<span style=\"color: #000000;\">3.0<\/span>\r\n<span style=\"color: #000000;\">-0.988031624093<\/span>\r\n<span style=\"color: #000000;\">-0.952412980415<\/span>\r\n<span style=\"color: #000000;\">1.61977519054<\/span>\r\n<span style=\"color: #000000;\">&gt;&gt;&gt;<\/span><\/pre>\n<p><span style=\"color: #000000;\">Screenshots:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2618 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module.png\" alt=\"\" width=\"407\" height=\"315\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module.png 407w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module-300x232.png 300w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module-388x300.png 388w\" sizes=\"(max-width: 407px) 100vw, 407px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2619 size-full\" src=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module_output.png\" alt=\"\" width=\"304\" height=\"282\" title=\"\" srcset=\"https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module_output.png 304w, https:\/\/cbsepython.in\/wp-content\/uploads\/2022\/02\/math_module_output-300x278.png 300w\" sizes=\"(max-width: 304px) 100vw, 304px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\">Check Here: <a href=\"https:\/\/cbsepython.in\/random-module-in-python-class-11-12-notes\/\">Random Function in Python Class 11 Notes<\/a><\/span><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to Python Module Class 11 Computer Science Python modules are a key concept in the Class 11 Computer Science (CBSE) syllabus and are commonly asked in board exams and practical assessments. A Python module is a program file that contains functions, variables, or classes which can be reused in other programs using the import [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,20],"tags":[],"class_list":["post-2597","post","type-post","status-publish","format-standard","hentry","category-cbse-sample-papers-class-11","category-cbse-computer-science-with-python-class-12"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/2597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=2597"}],"version-history":[{"count":2,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/2597\/revisions"}],"predecessor-version":[{"id":5575,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/2597\/revisions\/5575"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=2597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=2597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=2597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}