When writing a program, most of the times we will encounter errors. There are various possible reasons for which errors are generated. There are two distinguishable types of errors: syntax errors and exceptions.Syntax Erros:Not following the proper syntax of the programming language will generate a syntax error. It is also known as parsing error.Example:if a < … Continue reading Learning Python Part-25: Error and Exceptions
Category: Python
Learning Python Part-24: Recursive function, Lambda Function
Python Recursive Function:Recursion is the process of defining something in terms of itself. We know that in Python, a function can call other functions. It is even possible for the function to call itself. These type of construct are termed as recursive functions.Following is an example of recursive function to find the factorial of an integer.Factorial … Continue reading Learning Python Part-24: Recursive function, Lambda Function
Learning Python Part-23: Python Functions
In Python, function is a group of statements that perform a specific task. As we discussed about modules, how they help manage the code, Functions help break our program into smaller and modular chunks.As our program grows larger and larger, functions make it more organized and manageable.Furthermore, it avoids repetition and makes code reusable.Syntax: def … Continue reading Learning Python Part-23: Python Functions
Learning Python Part-22: Variable Scopes
Variable scope is the portion of the program from where a variable can be accessed directly without any prefix. Although there are unique variables defined, we may not be able to access all of them from every part of the program as they may be defined at various places like in main program, inside function, inside … Continue reading Learning Python Part-22: Variable Scopes
Learning Python Part-22: Python Flow Control
Before we go ahead and discuss about python flow control using if statements, for loop and while loop. Let's understand Python indentation quickly.Python Indentation:Programming languages like C, C++, Java use braces { } to define a block of code. However, Python uses indentation to define the code block. Indentation basically means, use of whitespaces.Generally 4 whitespaces (4 … Continue reading Learning Python Part-22: Python Flow Control
Learning Python Part-21: Python Files and Directories
Python Files:File is a named location on disk to store related information. It is used to store data in a non-volatile memory (e.g. hard disk) persistently. Since, random access memory (RAM) is volatile memory, it loses data whenever computer is turned off or rebooted, so we use files for storing the data.When we want to read … Continue reading Learning Python Part-21: Python Files and Directories
Learning Python Part-20: Python Modules and Python Package
Python Modules:We use modules to break down large programs into small manageable and organised files. We cannot keep on writing large programs in one python file. This approach may pose challenges like maintaining the code, debugging and few others. Using only one file for entire program may work for small programs and when only one … Continue reading Learning Python Part-20: Python Modules and Python Package