Legacy - Basic Functions Workout
- 03:50
Learn how to use basic functions in PyCharm.
Downloads
Basic Functions - Python Workout FilesTranscript
Let us now look at some basic functions in Python. These basic functions are used across some really complex functions. The base functions are print, STR for string, type, INT for integer, LEN for length. First, let us define a list called work. And this list consists of four numbers. Let us run this code, first, we need to use the run by right clicking on the tab. Because this is the first time we're running the file. Now, let's use the print function, the print function prints the output onto the output console, or the output area at the bottom of the pie chart. So if we ask print work, and run the code using shift after shortcut, or the icon at the top of the window, this would return an output of the list, which is 5, 10,15, 20. Perfect. Now, the STR function converts an item into a string. So before doing that, we need to know about the type function because this would let us know the initial type of the list. So the type function tells us if the list or the object in PyCharm is a string, integer or a float. So let us ask Python to print that type of work, which is our list and run it. So it's saying it's a list. Perfect, that's what we know. But if we want to convert this list into a string, so let us rename a work 2 which is the string of work list. And let us run this. Now, let's ask Python to print the type of work 2.
And let's run this. Perfect, it's a string the class is a string. Now, the next function that we're going to work with is that INT function. Before doing that, let us define a variable B, which is a string of just 100. Now, we clearly know that the type of B is a string, meaning B is a string data type, if we redefine a new variable A and use that INT function, convert B into an integer. Now, let's ask Python to print that type of be a sorry, which is an integer. So perfect, it's working. Why do we have to convert between strings and integers? It's based on the operation. If you're trying to apply different operators to the objects that Python we may want to convert between data types, once we may need an integer and another time we may need a string. Now, the last function is the LEN function, which is the length. So now let us look back at the list that we defined at the start, which is the work we know that it has four different elements. Let us apply the function length and see if we are right. So if we ask Python to print, the length of work, this should return an answer for which it does. The length LEN function calculates the length of the object the number of items within any object, in this case, the list spool.