Hey gang! I’m Tim from Core Electronics and today we're checking out a great reference piece for all the built-in functions of Python.
Functions literally give the functionality to a programming language and Python gives you many built-in functions, a function in Python is a block of code which only runs when it’s called it is organized, reusable and performs a single related action functions are all about making it easier for the user whilst increasing modularity and improving code reusability.
Remember when we use print in our first Python script? Right there is an example of a function. Now the built-in functions do not need to be imported and can be accessed instantly in your script as they are installed into Python by default, also you can import extra functionality through online packages or through built-in modules. Python truly becomes a powerhouse programming language when these external packages are used, now more on these and how to utilize them in a later tutorial, however for Python to retain its lightweight and speedy status by default it only permits access for a small core unit of functions this is unless the Pythonista decides otherwise.
The goal of this tutorial is to prevent you from being side swiped by some function that you've never heard of before or if there's a function you have not seen you'll be able to realize it is not part of the default Python selection of functions it is worth noting that it's possible to create your own personal functions which are referred to as user-defined functions, so when you're going through someone else’s code particularly one which has not been commented well you can run into user-defined functions without even realizing it having a grasp of all the inbuilt tools available to you will keep morale high and motivation to continue on your coding travels keeping that in mind I won't be giving a code example for each and every single one of these functions as a number of these are very rare for a beginner to encounter or use, this is more of an encouragement to immerse yourself into the Python lingo and to give yourself reference points for when you need.
So flying into the computer here, you can see the tutorial on our website with all the built-in functions of Python, scrolling down you can see the first table, this is built-in conversion functions, this is a selection of Python built-in functions all focused on converting one data type into another, all the tables in this guide will be in a similar format identifying them giving them a description for each of them and the syntax when you use them in Python scripts.
Data conversion is a very important facet of programming as modern humans tend to use base 10, whereas computers prefer to use base 2, ergo binary and sometimes compromises are made, things like hexadecimals using base 12, base 16 or octal strings using base 8 so for these conversion functions I have a quick code to demonstrate them. Here you can see A equals 9 a variable and B equals a very large number so the code goes print decimal print decimal A is A because A is already given as a number which is a decimal, print A as a binary number which involves using the function bin, print A as a hexadecimal number this is the function to turn A number into a hexadecimal and this is for octonumbers and I do the same for B so if we run this code right now you’ll see how these different numbers are represented inside Python and you can see hexadecimal because it's a base 169 pops up just as normal with a little zero and an X before just to demonstrate that it's a hexadecimal number when the numbers become very large in this case for B you can see the binary number becomes extremely large that's why these compromise kind of hexadecimal and octa decimal numbers are used because they make a very large number in binary become a lot smaller, also letters and numbers can be converted between each other using encoding standards such as ascii which is the American standard code for information interchange and also Unicode and both of these can be seen in the table.
Now if we scroll down further, the next table worth looking, at is the built-in type functions, variable type has already been talked about in a previous tutorial, these are all functions that if you want to specify the variable type you can do so using these functions, it’s worth noting that when creating a variable it is not necessary to specify the type although if you do you’ll reap more control over your code and scrolling down further here’s the doozy. This is all other built-in functions within python not including the ones above so with the first six these are the most commonly utilized functions and then the following are given in alphabetical order if the function is a Boolean or math type function it is explicitly mentioned with special tags to make them easier to find and like before the description of the Python function and the syntax of the written code is also given so as you're going through this table if you see any forward slashes like here, this represents a place in the function for a keyword argument now definitely do not feel the need to memorize all of this just take the time to wander through and smell the roses if you want, the intention for this is to be a reference point a place for you to come back to and feel as though nothing is being hit! I hope this has been helpful and inspired future programming endeavours in your life, until next time stay cosy!
Makers love reviews as much as you do, please follow this link to review the products you have purchased.