+ INFORMATION

Share on social networks!

Predefined functions in Python

A function it's a code block, which receives zero or more arguments and performs an operation to return a value and/or performs a specific task. The functions must have a assigned name to be able to “call” them during the execution of the program and they are completely reusable.

Although you can create all kinds of functions, today we are going to focus on those that come by default integrated into Python. If you want to develop your career in Python, we recommend you visit our master in Advanced Programming in Python for Big Data, Hacking and Machine Learning and train with the best experts.

To start we can use the function dir() to list all predefined functions. We can get help from different functions with help(), for example the function max():

Most notable predefined functions

  • list() Create a list from an element.
  • tuple() Create or convert to a tuple.
  • type() Returns the type of the element passed as a parameter.

To work with text:

  • print() Prints on the screen the argument that we pass to it 
  • len() It returns the length in characters of the string that we pass as a parameter
  • replace() Replaces a string with the one it includes as an argument.
  • upper() Converts the string passed as an argument to uppercase
  • lower() Converts the string passed as an argument to lowercase

And the most used numerical functions:

  • sum() Sums the list of numbers passed as an argument.
  • min() Determines the minimum value of a list of numbers passed as an argument.
  • max() Determines the maximum value of a list of numbers passed as an argument.
  • range() Creates an arithmetic list of numbers based on the value passed as an argument.
  • str() Converts a numeric value to text.

There are many more predefined functions in Python, you can learn to use them and even create functions yourself.

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SA as the person responsible for this website. The purpose of collecting and processing personal data is to respond to the query made as well as to send information about the services of the data controller. Legitimation is the consent of the interested party.
You can exercise your rights of access, rectification, limitation and deletion of data in compliance@grupomainjobs.com as well as the right to file a claim with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find in our Web page
marter-in-python

Leave a comment