Category: python basic

python tutorials and learn python

Created with Sketch.

Python -Module

Python Module Any text file with the .py extension containing Python code is basically a module. Different Python objects such as functions, classes, variables, constants, etc., defined in one module can be made available to an interpreter session or another Python script by using the import statement. Functions defined in built-in modules need to be…
Read more

Python – Local and Global Variables

Python – Local and Global Variables In general, a variable that is defined in a block is available in that block only. It is not accessible outside the block. Such a variable is called a local variable. Formal argument identifiers also behave as local variables. The following example will underline this point. An attempt to…
Read more

Python – Lambda function

Python – Lambda function Normally we use the def keyword to define a function with a name. The lambda keyword is used to create anonymous functions. Usually, such a function is meant for one-time use. Syntax: lambda arg1, arg2… : expression The lambda function can have any number of arguments but there’s always a single…
Read more

Python – User-Defined Functions

Python – User-Defined Functions Python includes many built-in functions. These functions perform a predefined task and can be called upon in any program, as per requirement. However, if you don’t find a suitable built-in function to serve your purpose, you can define one. We will now see how to define and use a function in…
Read more

Python – range Function

Python – range Function In Python, the range() method returns an immutable sequence of numbers. It can be used to control the repetition of a block in the for loop. Syntax: range([start], stop, [step])   All three parameters should be integers. The sequence starts with 0, by default, unless the [start] parameter is provided. The…
Read more

Python – pass Keyword

Python – pass Keyword The pass keyword as the name suggests does nothing. It is used as a dummy place holder whenever a syntactical requirement of a certain programming element is to be fulfilled without assigning any operation. In other words, the pass statement is simply ignored by the Python interpreter and can be seen…
Read more

Python – continue Keyword

Python – continue Keyword The effect of a continue statement is somewhat opposite to the break keyword. Instead of abandoning the pending iterations in the loop, the continue statement skips the remaining statements in the current loop and starts the next iteration. Usage of continue in Python is shown below: Example: continue num=0 while num<5:…
Read more

Python – break Keyword

Python – break Keyword The break keyword causes the abandonment of pending iterations of the current loop. The execution of the program jumps to the statement immediately after the body of the loop. Typical use of break is found in a sequential search algorithm. For example, if you need to search for an object in…
Read more

Python – else in Loop

Python – else in Loop As you have learned before, the else clause is used along with the if statement. Python allows the else keyword to be used with the for and while loops too. The else block appears after the body of the loop. The statements in the else block will be executed after…
Read more

Python – For Loop

Python – For Loop Python’s for keyword provides a more comprehensive mechanism to constitute a loop. The for loop is used with sequence types such as list, tuple and set. The body of the for loop is executed for each member element in the sequence. Hence, it doesn’t require explicit verification of Boolean expression controlling…
Read more