Python has functions and methods to manipulate files . No external library is required for doing file operations in python. In this tutorial, we will learn different python file operations like reading the content of a file, writing to a file etc.
ReadThe factorial of a number is the product of all the numbers from 1 to that number. e.g. factorial of 5 is 1 * 2 * 3 * 4 * 5 i.e. 120 . In this tutorial, we will learn how to find out the factorial of a number using a recursive method.
ReadWhat is a python package ? In simple words , python packages are directories containing python files. We love to arrange files in our computer in different directories, like all movies in a “movie” folder or all songs in a “songs” folder etc.
ReadA python module is simply a python file ( .py file ) with definitions and statements. The file name is the module name. After creating a module, we can use it any other module using “import” command.
ReadAnonymous or lambda functions are functions without a name. In python, we can create an anonymous function using a construct called “lambda” unlike “def” keyword we use to create other functions.
ReadSuppose you need to find the factorial of a number and you wrote a loop to calculate it. Again in the same project, factorial calculation is required again for a different number. In this case, we can write one similar “for” loop as before . But don’t you think that it would be better if we write the “for” loop only for one time and on second case, we will just run it using a “name” ? That will be great, if factorial is required to calculate in thousands of places, we don’t have to duplicate the same code again and again. These types of “ reusable code block that performs a specific task” is known as function.
ReadIn our last tutorial, we have seen that we can use “else" with “for” and “while” loop. Using “break”, we can stop the execution of a code block inside a loop. The control will next move to the next line after the body of the loop. If we use “break” inside a inner loop, the control will move to the outer loop.Let's take a look into the python break , continue and pass statements :.
ReadLoops are used in programming language to run a piece of code again and again. In this tutorial, we will check two types of looping in python - “while” loop and “for” loop.
ReadIf - else statements are known as conditional statements. In simple words, if the condition defined for “if” block is true, then the block of statements defined for if block will execute. Otherwise, the code defined for “else” block will execute.
ReadIn our previous tutorial, we have seen how to create a python dictionary and some built-in methods. In this tutorial, we will explore some more dictionary functions, methods and uses.
Read