# Modules¶

Modules are a way to store and install reusable Python code. You can create your own modules by defining a set of functions that may be useful to other developers, and packaging these functions in a specific way so the other developers can download and easily integrate your code into their projects.

To define a module, lets create a new file called `fibo.py` in your current directory. Lets add the following code:

``````def fib(n):    # write Fibonacci series up to n
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()

def fib2(n):   # return Fibonacci series up to n
result = []
a, b = 0, 1
while a < n:
result.append(a)
a, b = b, a+b
return result
``````

Now that we have some functions defined, how do we access them? Let's open the Python shell (or create a new file), and run/create:

``````import fibo

fibo.fib(10)

res = fibo.fib2(10)
print(res)
``````

Now we have created and called our very own Python module! We can also import specific functions instead of the whole module, like this:

``````from fibo import fib

fib(10)
``````

In further labs, we will see how you can view the contents of a given module using the dir() functionality.
{"ft_lang_label":"__label__en","ft_lang_prob":0.77428705,"math_prob":0.7379158,"size":1252,"snap":"2021-43-2021-49","text_gpt3_token_len":316,"char_repetition_ratio":0.10977564,"word_repetition_ratio":0.06451613,"special_character_ratio":0.25479233,"punctuation_ratio":0.13754646,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9805224,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-11-29T07:46:04Z\",\"WARC-Record-ID\":\"<urn:uuid:2c68a4b0-27e0-486e-a591-4fe06bf1c5f7>\",\"Content-Length\":\"34193\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b7562329-b46b-4445-9f6b-91376b9d8e3f>\",\"WARC-Concurrent-To\":\"<urn:uuid:cfbcc91a-b6be-4149-8bb7-1cf76fca1e35>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://www.coderdojotc.org/python/intermediate/07-modules/\",\"WARC-Payload-Digest\":\"sha1:22ARV4XSGQXOCBEAE7GYBJYLSVJ3ILJE\",\"WARC-Block-Digest\":\"sha1:R5BAMFD47V62URSID2BTTEBGB6HGTFKP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964358702.43_warc_CC-MAIN-20211129074202-20211129104202-00111.warc.gz\"}"}