0

What is the only main difference between built-in functions and modules in python ?

Explain the main difference between built-in functions and modules in python.Why these modules are stored in specific packages and libraries ?

22nd May 2020, 2:49 AM
Ashwini Burnwal
Ashwini Burnwal - avatar
2 odpowiedzi
+ 1
Python Function : A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Python gives you many built-in functions like print(), etc. but you can also create your own functions. These functions are called user-defined functions. # Function definition is here def printme( str ): "This prints a passed string into this function" print str return; # Now you can call printme function printme("Call user defined function") printme("Again Call user defined function") Output : Call user defined function Again Call user defined function Python Module : A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand and use. A module is a Python object with arbitrarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code. Here's an example of a simple module that define in support.py def print_func( par ): print "Hello : ", par return For example, to import the module support.py, you need to put the following command at the top of the script − # Import module support import support # Now you can call defined function that module as follows support.print_func("Kamal Swami") Output : Hello :Kamal Swami
22nd May 2020, 3:17 AM
Kamal
Kamal - avatar
+ 1
A module is group of statements that exist within a program for the purpose of performing a specific task. A function is a type of module that returns a value back to the program that called it.
22nd May 2020, 4:33 AM
Vaishnavi Rajkumar Pawar