And the nameattribute tells you the name of the file. They can also be used to manipulate said file.įor example, the modeattribute of a file object tells you which mode a file was opened in. File objects contain methods and attributes that can be used to collect information about the file you opened. We will more about functions and modules in later sessions.When you use the openfunction, it returns something called a file object. In our example, print function takes the string as the argument and displays it. Like for sin(x) function, we need to pass an argument which is the measure of an angle sin(x).įunctions may take more than one argument also. There are three types of Python functions:Ī) Python build-in functions: They come with Python itself and you can use them directly like print.ī) Python modules – They also come with Python but to use them, you need to import them from their parent space like ‘sin’, ‘cos’ etc.Ĭ) User-Defined Functions – Functions which a user can code themselves like finding the speed of a vehicle if we know the distance travelled in time.įunctions may take arguments to evaluate something. There are functions which can perform both the above activities also. Generally, a Python function performs two activities:Ī) Cause some effect – like print functionī) Evaluates some value – like sum, sin, cos which we will see later Python function is a piece of code that performs some action or causes some effect. Let’s put some attention and time to see what functions are: It takes the string as an input/argument and displays the string on the console. So print is a function that displays the desired result for you.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |