Category: Tutorials
-
Keyword Arguments
Keyword Arguments Python allows to pass function arguments in the form of keywords which are also called named arguments. Variables in the function definition are used as keywords. When the function is called, you can explicitly mention the name and its value. Calling Function With Keyword Arguments The following example demonstrates keyword arguments in Python. In the second function…
-
Default Arguments
Python Default Arguments Python allows to define a function with default value assigned to one or more formal arguments. Python uses the default value for such an argument if no value is passed to it. If any value is passed, the default value is overridden with the actual value passed. Default arguments in Python are the function arguments that…
-
Functions
A Python function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. A top-to-down approach towards building the processing logic involves defining blocks of independent reusable functions. A Python function may be invoked from…
-
Nested Loops
In Python, when you write one or more loops within a loop statement that is known as a nested loop. The main loop is considered as outer loop and loop(s) inside the outer loop are known as inner loops. The Python programming language allows the use of one loop inside another loop. A loop is a code block that executes…
-
pass Statement
Python pass Statement Python pass statement is used when a statement is required syntactically but you do not want any command or code to execute. It is a null which means nothing happens when it executes. This is also useful in places where piece of code will be added later, but a placeholder is required to ensure…
-
Continue Statement
Python continue Statement Python continue statement is used to skip the execution of the program block and returns the control to the beginning of the current loop to start the next iteration. When encountered, the loop starts next iteration without executing the remaining statements in the current iteration. The continue statement is just the opposite to that of break. It skips the…
-
Break Statement
Python break Statement Python break statement is used to terminate the current loop and resumes execution at the next statement, just like the traditional break statement in C. The most common use for Python break statement is when some external condition is triggered requiring a sudden exit from a loop. The break statement can be used in both Python while and for loops. If you are…
-
While Loops
Python while Loop A while loop in Python programming language repeatedly executes a target statement as long as the specified boolean expression is true. This loop starts with while keyword followed by a boolean expression and colon symbol (:). Then, an indented block of statements starts. Here, statement(s) may be a single statement or a block of statements with uniform indent.…
-
Else Loops
Python – For Else Loop Python supports an optional else block to be associated with a for loop. If a else block is used with a for loop, it is executed only when the for loop terminates normally. The for loop terminates normally when it completes all its iterations without encountering a break statement, which allows us to exit the loop when…
-
For Loops
The for loop in Python provides the ability to loop over the items of any sequence, such as a list, tuple or a string. It performs the same action on each item of the sequence. This loop starts with the for keyword, followed by a variable that represents the current item in the sequence. The in keyword links the variable to…