Tutorial Python 12: Functions - Printable Version +- Red Security (https://redsecurity.info/cc) +-- Forum: Programming (https://redsecurity.info/cc/forumdisplay.php?fid=5) +--- Forum: Python (https://redsecurity.info/cc/forumdisplay.php?fid=9) +--- Thread: Tutorial Python 12: Functions (/showthread.php?tid=7897) |
Python 12: Functions - Covid-19 - 04-24-2022 Functions: We have mentioned a lot of functions in our program even though the print statement is also a function. We have used a lot of functions in our previous code but now we will understand deeply how these functions are created and used and how you can make your own functions. Function is a block of code which performs some specific task. To revise, here are some example function.. Quote:print("Hello world!") Functions divide our code into smaller parts which are really helpful in debugging (Process of finding and removing errors). The word before parenthesis is the name of the function and inside the parenthesis are attributes. Function makes our code manageable when we are working on a complex program. We have built-in functions for lists and strings; these are known as built-in functions. Let’s see some other functions we can use with lists. index(): This function returns the index of an element in the list. Code: # Program to demonstrate index function max(list): This function will return the maximum number in the list Code: # Program to demonstrate max function min(list): This will return the minimum number of list sort(list): This will sort the list To check more function check out this link Quote:https://www.w3schools.com/python/python_ref_list.asp Now let’s check out some string method/functions splitlines(): Splits the string at line breaks and returns a list startswith(): Returns true if a string starts with a specified value swapcase(): It will swap the case of string if it is lower it will convert it into capital and vice versa To know more about string functions check out the link below Quote:https://www.w3schools.com/python/python_ref_string.asp Now, let’s talk about user-defined functions. These are the functions defined by programmers you can create your own function by using a keyword ‘def’ now let’s write code Code: # Program to make a user defined function You can call a function by its name as in above program function is called once. But you can call a function as many times as you want. You can also pass arguments to your function. Arguments are the variables only in that specific function. Let’s check the code for this concept Code: # Program to find factorial of a number That’s it for today. It is the last thread for python beginners. Congrats for completing beginners for Python. After that we will be diving into more cool concept of Python This is just a beginning.. "So, Keep Good care of your Health Allah Hafiz and Good Bye Till the next post" "Keep Learning and Keep exploring" RE: Python 12: Functions - Mr.Kurd - 04-26-2022 Thanks again for an amazing tutorial RE: Python 12: Functions - Covid-19 - 04-27-2022 (04-26-2022, 07:40 PM)Mr.Kurd Wrote: Thanks again for an amazing tutorial Thank you very much |