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>Yes.  Let's say you're writing code in a file called <code>palindrome.py</code>.  Then in another file, or in the python shell you want to use that code.  You would type</p>

<pre><code>import palindrome
</code></pre>

<p>either at the top of the file or just into the shell as a command.  Then you can access functions you've written in <code>palindrome.py</code> with statements like</p>

<pre><code>palindrome.is_palindrome('abba')
</code></pre>

<p>It's important to note that to do this propery, the code in <code>palindrome.py</code> must be in functions.  If you're not sure how to do that, I recommend the official Python tutorial: <a href="https://docs.python.org/3/tutorial/index.html" rel="nofollow">https://docs.python.org/3/tutorial/index.html</a></p>

python function module