how to make a python module or fuction and use it while writing other programs?
<p>There where many instances where i have to write large line of code over and over again in multiple programs. so i was wondering if i could write just one program, save it and then  call it in different programs like a function or a module.</p>

<p>An elementary example :- I write a program to check if a number is palindromic or not. Then i want to write a program to check if a number is a palindromic a prime, could i just call the first program and do the rest of the code to check if it is prime or not.</p>

<p>P.S I'm just a beginner at python or computer science for that matter and i use IDLE to do all my python programs.</p>

<p>It is about writing reusable code. I can suggest you to write reusable code in specific function in separate python file and import that file and function too.
For example you need function called sum in other function called "bodmas" then write function called sum in one python file say suppose "allimports.py":</p>

<pre><code>    def sum(a,b):
      return a+b
</code></pre>

<p>Now suppose your "bodmas" named function is some other python file then just import all the required functions and use is normally by calling it.</p>

<pre><code>    from allimports import sum
    def bodmas:
       print(sum(1,1))
</code></pre>

<p>One important thing is be specific while import your module as it will effect performance of your code when length of your code is long.
Suppose you want to use all functions then you can use two option like :</p>

<pre><code>    import allimports
    print(allimports.sum(1,1))
</code></pre>

<p>other option is </p>

<pre><code>    from allimports import *
    print(sum(1,1))
</code></pre>

<p>and for specific imports is as follows:</p>

<pre><code>    from allimports import sum
    print(sum(1,1))
</code></pre>

python function module