Python Tutorial Guides

Articles

description

"Thread Priority in Python: Managing Thread Execution Importance

The queue module in Python's standard library is useful in threaded programming when information must be exchanged safely between multiple…

arrow_forward
description

"Python Dynamic Binding: Late Binding in Object-Oriented Programming

In object-oriented programming, the concept of dynamic binding is closely related to polymorphism. In Python, dynamic binding is the…

arrow_forward
description

"Python Encapsulation: Data Hiding and Access Control in OOP

The principle of Encapsulation is one of the main pillars on which the object-oriented programming paradigm is based. Python takes a…

arrow_forward
description

"Python File Methods: File Manipulation Functions

A file object is created using open() function. The file class defines the following methods with which different file IO operations can be…

arrow_forward
description

"Python Tuple Exercises: Practice for Tuple Manipulation"

Example 1 Python program to find unique numbers in a given tuple −   T1 = (1, 9, 1, 6, 3, 4, 5, 1, 1, 2, 5, 6, 7, 8, 9, 2) T2 = () for x…

arrow_forward
description

"Working with Arrays in Python: Numerical Data Structures

Python's standard data types list, tuple and string are sequences. A sequence object is an ordered collection of items. Each item is…

arrow_forward
description

Accessing Array Items in Python: Retrieving Elements from Arrays

Since the array object behaves very much like a sequence, you can perform indexing and slicing operation with it. Example   import array…

arrow_forward
description

Accessing Dictionary Items in Python: Retrieving Values by Keys

Using the "[ ]" Operator A dictionary in Python is not a sequence, as the elements in dictionary are not indexed. Still, you can use the…

arrow_forward
description

Accessing List Items in Python: Retrieving Elements from Lists

In Python, a list is a sequence. Each object in the list is accessible with its index. The index starts from 0. Index or the last item in…

arrow_forward
description

Accessing Set Items in Python: Retrieving Elements from Sets

Since set is not a sequence data type, its items cannot be accessed individually as they do not have a positional index (as in list or…

arrow_forward
description

Accessing Tuple Items in Python: Retrieving Elements from Tuples

In Python, Tuple is a sequence. Each object in the list is accessible with its index. The index starts from "0". Index or the last item in…

arrow_forward
description

Adding Array Items in Python: Appending Elements to Arrays

The append() Method The append() method adds a new element at the end of given array. Syntax array.append(v) Parameters v − new…

arrow_forward
description

Adding Dictionary Items in Python: Inserting Key-Value Pairs

Using the Operator The "[]" operator (used to access value mapped to a dictionary key) is used to update an existing key-value pair as…

arrow_forward
description

Adding List Items in Python: Appending and Inserting Elements

There are two methods of the list class, append() and insert(), that are used to add items to an existing list. Example 1 The append()…

arrow_forward
description

Adding Set Items in Python: Including Elements in Sets

Even if a set holds together only immutable objects, set itself is mutable. We can add new items in it with any of the following ways −…

arrow_forward
description

CGI Programming in Python: Creating Dynamic Web Content

The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom…

arrow_forward
description

Changing Dictionary Items in Python: Modifying Key-Value Pairs

Apart from the literal representation of dictionary, where we put comma-separated key:value pairs in curly brackets, we can create…

arrow_forward
description

Changing List Items in Python: Modifying Elements in Lists

List is a mutable data type in Python. It means, the contents of list can be modified in place, after the object is stored in the memory.…

arrow_forward
description

Command-Line Arguments in Python: Handling Input Parameters

To run a Python program, we execute the following command in the command prompt terminal of the operaing system. For example, in windows,…

arrow_forward
description

Comparing Python and C++

Both Python and C++ are among the most popular programming languages. Both of them have their advantages and disadvantages. In this…

arrow_forward
description

Copying Arrays in Python: Creating Duplicate Arrays

Python's built-in sequence types i.e. list, tuple and string are indexed collection of items. However, unlike arrays in C/C++, Java etc. ,…

arrow_forward
description

Copying Dictionaries in Python: Creating Duplicate Dictionaries

Since a variable in Python is merely a label or reference to an object in the memory, a simple assignment operator will not create copy of…

arrow_forward
description

Copying Lists in Python: Duplicating List Contents

In Python, a variable is just a label or reference to the object in the memory. Hence, the assignment "lst1 = lst" refers to the same list…

arrow_forward
description

Copying Sets in Python: Creating Duplicates of Sets

The copy() method in set class creates a shallow copy of a set object. Syntax set.copy() Return Value The copy() method returns a new…

arrow_forward
description

Creating Threads in Python: Concurrent Execution for Parallel Tasks

The start_new_thread() function included in the _thread module is used to create a new thread in the running program. Syntax…

arrow_forward
description

Creating a Python Hello World Program

This tutorial will teach you how to write a simple Hello World program using Python Programming language. This program will make use of…

arrow_forward
description

Daemon Threads in Python: Background Threads for Supporting Tasks

Sometimes, it is necessary to execute a task in the background. A special type of thread is used for background tasks, called a daemon…

arrow_forward
description

Data Compression in Python: Reducing File Sizes and Improving Efficiency

Python's standard library has a rich collection of modules for data compression and archiving. One can select whichever is suitable for his…

arrow_forward
description

Database Access in Python: Connecting and Querying Databases

Data input and generated during execution of a program is stored in RAM. If it is to be stored persistently, it needs to be stored in…

arrow_forward
description

Date and Time Handling in Python: Working with Temporal Data

A Python program can handle date and time in several ways. Converting between date formats is a common chore for computers. Following…

arrow_forward
description

Exploring Python String Methods: Text Manipulation in Python"

Python's built-in str class defines different methods. They help in manipulating strings. Since string is an immutable object, these…

arrow_forward
description

Exploring Python and the Unicode System

Software applications often require to display messages output in a variety in different languages such as in English, French, Japanese,…

arrow_forward
description

Exploring Python's Fundamental Syntax

The Python syntax defines a set of rules that are used to create Python statements while writing a Python Program. The Python Programming…

arrow_forward
description

Exploring Python's Key Characteristic

Python is a feature rich high-level, interpreted, interactive and object-oriented scripting language. This tutorial will list down some of…

arrow_forward
description

File Handling in Python: Working with File I/O

When we use any computer application, some data needs to be provided. Data is stored in computer's main memory (RAM) until the application…

arrow_forward
description

GUI Programming in Python: Building Graphical User Interfaces

Python provides various options for developing graphical user interfaces (GUIs). The most important features are listed below. Tkinter…

arrow_forward
description

Generics in Python: Flexible Data Types for Code Reusability

In Python, generics is a mechanism with which you to define functions, classes, or methods that can operate on multiple types while…

arrow_forward
description

Inter-Thread Communication in Python: Coordinating Parallel Execution

Threads share the memory allocated to a process. As a result, threads in the same process can communicate with each other. To facilitate…

arrow_forward
description

Interrupting a Thread in Python: Graceful Termination of Concurrent Execution

In a multi-threaded program, a task in a new thread, may be required to be stopped. This may be for many reasons, such as: (a) The result…

arrow_forward
description

JSON Processing in Python: Interchanging Data with JSON Format

JSON stands for JavaScript Object Notation. It is a lightweight data interchange format. It is similar to pickle. However, pickle…

arrow_forward
description

Joining Arrays in Python: Combining Multiple Arrays

In Python, array is a homogenous collection of Python's built in data types such as strings, integer or float objects. However, array…

arrow_forward
description

Joining Lists in Python: Combining Multiple Lists

In Python, List is classified as a sequence type object. It is a collection of items, which may be of different data types, with each item…

arrow_forward
description

Joining Sets in Python: Combining Multiple Sets

In Python, a Set is an ordered collection of items. The items may be of different types. However, an item in the set must be an immutable…

arrow_forward
description

Joining Threads in Python: Synchronizing Concurrent Execution

The join() method in thread class blocks the calling thread until the thread whose join() method is called terminates. The termination may…

arrow_forward
description

Joining Tuples in Python: Combining Multiple Tuples

In Python, a Tuple is classified as a sequence type object. It is a collection of items, which may be of different data types, with each…

arrow_forward
description

Logging in Python: Recording Events and Debugging Information

The term "logging" refers to the mechanism of recording different intermediate events in a certain process. Recording logs in a software…

arrow_forward
description

Looping Through Arrays in Python: Iterating Over Array Elements

Since the array object behaves like a sequence, you can iterate through its elements with the help of for loop or while loop. "for" Loop…

arrow_forward
description

Looping Through Dictionaries in Python: Iterating Over Key-Value Pairs

Unlike a list, tuple or a string, dictionary data type in Python is not a sequence, as the items do not have a positional index. However,…

arrow_forward
description

Looping Through Lists in Python: Iterating Over List Elements

You can traverse the items in a list with Python's for loop construct. The traversal can be done, using list as an iterator or with the…

arrow_forward
description

Looping Through Sets in Python: Iterating Over Set Elements

A set in Python is not a sequence, nor is it a mapping type class. Hence, the objects in a set cannot be traversed with index or key.…

arrow_forward
description

Looping Through Tuples in Python: Iterating Over Tuple Elements

You can traverse the items in a tuple with Python's for loop construct. The traversal can be done, using tuple as an iterator or with the…

arrow_forward
description

Managing Python Virtual Environments

In this chapter, you will get to know what a virtual environment in Python is, how to create and use a virtual environment for building a…

arrow_forward
description

Mathematical Operations in Python: Working with Numbers

Python's standard library provides math module. This module includes many pre-defined functions for performing different mathematical…

arrow_forward
description

Modifying Strings in Python: Manipulating Text Data

In Python, a string (object of str class) is of immutable type. An immutable object is the one which can be modified in place, one created…

arrow_forward
description

Multithreading in Python: Concurrent Execution for Improved Performance

By default, a computer program executes the instructions in a sequential manner, from start to the end. Multithreading refers to the…

arrow_forward
description

Naming Threads in Python: Identifying Concurrent Execution Units

The name of a thread is for identification purpose only, and has no role as far as the semantics is concerned. More than one threads may…

arrow_forward
description

Nested try Blocks in Python: Handling Exceptions within Exceptions

In a Python program, if there is another try-except construct either inside either a try block or inside its except block, it is known as a…

arrow_forward
description

Network Programming in Python: Building Networked Applications

The threading module in Python's standard library is capable of handling multiple threads and their interaction within a single process.…

arrow_forward
description

Output Formatting in Python: Structuring Displayed Data

In this chapter, different techniques for formatting the output will be discussed. String Formatting Operator One of Python's coolest…

arrow_forward
description

Performance Measurement in Python: Analyzing Code Execution

A given problem may be solved by more than one alternative algorithms. Hence, we need to optimize the performance of the solution. Python's…

arrow_forward
description

Python Abstraction: Simplifying Complexity in Object-Oriented Code

Abstraction is one of the important principles of object-oriented programming. It refers to a programming approach by which only the…

arrow_forward
description

Python Access Modifiers: Controlling Visibility in Classes

The languages such as C++ and Java, use access modifiers to restrict access to class members (i.e., variables and methods). These languages…

arrow_forward
description

Python Anonymous Classes and Objects: Dynamic Object Creation

Python's built-in type() function returns the class that an object belongs to. In Python, a class, both a built-in class or a user-defined…

arrow_forward
description

Python Arbitrary Arguments: Handling Variable-Length Inputs

You may want to define a function that is able to accept arbitrary or variable number of arguments. Moreover, the arbitrary number of…

arrow_forward
description

Python Arithmetic Operators: Mathematical Operations in Python

In Python, numbers are the most frequently used data type. Python uses the same symbols for basic arithmetic operations Everybody is…

arrow_forward
description

Python Array Exercises: Practice for Array Manipulation

Example 1 Python program to find the largest number in an array −   import array as arr a = arr.array('i', [10,5,15,4,6,20,9]) print (a)…

arrow_forward
description

Python Array Methods: Effective Array Operations

array.reverse() Method Like the sequence types, the array class also supports the reverse() method which rearranges the elements in…

arrow_forward
description

Python Assertions: Debugging and Error Detection in Code

An assertion is a sanity-check that you can turn on or turn off when you are done with your testing of the program. The easiest way to…

arrow_forward
description

Python Assignment Operators: Assigning Values in Python

The = (equal to) symbol is defined as assignment operator in Python. The value of Python expression on its right is assigned to a single…

arrow_forward
description

Python Augmented Addition Operator (+=): Incremental Value Assignment"

This operator combines addition and assignment in one statement. Since Python supports mixed arithmetic, the two operands may be of…

arrow_forward
description

Python Bitwise Operators: Manipulating Binary Data in Python

Python’ bitwise operators are normally used with integer type objects. However, instead of treating the object as a whole, it is treated…

arrow_forward
description

Python Booleans: Managing True and False Values in Python

In Python, bool is a sub-type of int type. A bool object has two possible values, and it is initialized with Python keywords, True and…

arrow_forward
description

Python Built-in Exceptions: Common Error Types in Python

Here is a list of Standard Exceptions available in Python − Sr.No. Exception Name & Description 1 Exception Base class…

arrow_forward
description

Python Built-in Functions: Essential Tools for Python Programmers

As of Python 3.11.2 version, there are 71 built-in functions in Pyhthon. The list of built-in functions is given below − Sr.No.…

arrow_forward
description

Python Class Attributes: Shared Data for Class Instances

Every Python class keeps the following built-in attributes and they can be accessed using dot operator like any other attribute −…

arrow_forward
description

Python Class Methods: Functions Associated with Classes

An instance method accesses the instance variables of the calling object because it takes the reference to the calling object. But it can…

arrow_forward
description

Python Closures: Encapsulating and Preserving Function State

In this chapter, let us discuss the concept of closures in Python. In Python, functions are said to be first order objects. Just like the…

arrow_forward
description

Python Comments: Annotating Your Code in Python

Python comments are programmer-readable explanation or annotations in the Python source code. They are added with the purpose of making the…

arrow_forward
description

Python Comparison Operators: Comparing Values in Python

Comparison operators in Python are very important in Python’s conditional statements (if, else and elif) and looping statements (while…

arrow_forward
description

Python Constructors: Initializing Objects in Classes

In object-oriented programming, an object of a class is characterized by one or more instance variables or attributes, whose values are…

arrow_forward
description

Python Continue Statement: Skipping Iterations in Loops

The continue statement in Python returns the control to the beginning of the current loop. When encountered, the loop starts next iteration…

arrow_forward
description

Python Control Flow: Managing Program Execution

By default, the instructions in a computer program are executed in a sequential manner, from top to bottom, or from start to end. However,…

arrow_forward
description

Python Data Types Explained

Computer is a data processing device. Computer stores the data in its memory and processes it as per the given program. Data is a…

arrow_forward
description

Python Decision Making: Controlling Program Flow in Python

Python’s decision making functionality is in its keywords – if, else and elif. The if keyword requires a boolean expression, followed…

arrow_forward
description

Python Decorators: Enhancing Functions with Metadata

A Decorator in Python is a function that receives another function as argument. The argument function is the one to be decorated by…

arrow_forward
description

Python Default Arguments: Enhancing Function Flexibility

arrow_forward
description

Python Dictionary Exercises: Practice for Dictionary Manipulation

Example 1 Python program to create a new dictionary by extracting the keys from a given dictionary.   d1 = {"one":11, "two":22,…

arrow_forward
description

Python Dictionary Methods: Efficient Dictionary Operations

A dictionary in Python is an object of the built-in dict class, which defines the following methods − Sr.No. Method and Description…

arrow_forward
description

Python Dictionary View Objects: Dynamic Views of Dictionary Data

The items(), keys() and values() methods of dict class return view objects. These views are refreshed dynamically whenever any change…

arrow_forward
description

Python Docstrings: Documenting Code for Clarity and Understanding

In Python, a docstring is a string literal that serves as the documentation of different Python objects such as functions, modules, class…

arrow_forward
description

Python Dynamic Typing: Flexible Variable Types

One of the standout features of Python language is that it is a dynamically typed language. The compiler-based languages C/C++, Java, etc.…

arrow_forward
description

Python Enums: Named Constants for Improved Code Clarity

The term 'enumeration' refers to the process of assigning fixed constant values to a set of strings, so that each string can be identified…

arrow_forward
description

Python Escape Characters: Special Text Handling in Python

In Python, a string becomes a raw string if it is prefixed with "r" or "R" before the quotation symbols. Hence 'Hello' is a normal string…

arrow_forward
description

Python Exception Chaining: Propagating and Handling Multiple Exceptions

Exception chaining is a technique of handling exceptions by re-throwing a caught exception after wrapping it inside a new exception. The…

arrow_forward
description

Python Exception Handling: Graceful Error Management in Code

If you have some suspicious code that may raise an exception, you can defend your program by placing the suspicious code in a try: block.…

arrow_forward
description

Python Extensions: Expanding Functionality and Features"

Any code that you write using any compiled language like C, C++, or Java can be integrated or imported into another Python script. This…

arrow_forward
description

Python Function Annotations: Adding Metadata to Functions

The function annotation feature of Python enables you to add additional explanatory metada about the arguments declared in a function…

arrow_forward
description

Python Functions: Modularizing Code in Python

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for…

arrow_forward
description

Python GUIs: Creating Graphical User Interfaces with Ease

arrow_forward
description

Python Generators: Efficient Iteration with Lazy Evaluation

A generator in Python is a special type of function that returns an iterator object. It appears similar to a normal Python function in that…

arrow_forward
description

Python Identity Operators: Comparing Object Identities

Python has two identity operators is and is not. Both return opposite Boolean values. The "in" operator evaluates to True if both the…

arrow_forward
description

Python Inheritance: Building Hierarchical Class Structures

Inheritance is one of the most important features of Object-oriented programming methodology. It is most often used in software development…

arrow_forward
description

Python Inner Classes: Nested Classes for Modularity

A class defined inside another class is known as an inner class in Python. Sometimes inner class is also called nested class. If the inner…

arrow_forward
description

Python Interfaces: Defining Contracts for Class Implementations

In software engineering, an interface is a software architectural pattern. An interface is like a class but its methods just have prototype…

arrow_forward
description

Python Iterators: Efficient Sequential Data Processing

Iterator in Python is an object representing a stream of data. It follows iterator protocol which requires it to support __iter__() and…

arrow_forward
description

Python Keyword Arguments: Enhancing Function Call Clarity

Keyword argument are also called named arguments. Variables in the function definition are used as keywords. When the function is called,…

arrow_forward
description

Python Keyword-Only Arguments: Fine-Tuning Function Parameters

You can use the variables in formal argument list as keywords to pass value. Use of keyword arguments is optional. But, you can force the…

arrow_forward
description

Python List Comprehension: Compact List Transformations

List comprehension is a very powerful programming tool. It is similar to set builder notation in mathematics. It is a concise way to create…

arrow_forward
description

Python List Exercises: Practice for List Manipulation

Example 1 Python program to find unique numbers in a given list.   L1 = [1, 9, 1, 6, 3, 4, 5, 1, 1, 2, 5, 6, 7, 8, 9, 2] L2 = [] for x…

arrow_forward
description

Python List Methods: Powerful List Operations

Python's list class includes the following methods using which you can add, update, and delete list items − Sr.No Methods &…

arrow_forward
description

Python Literals: Constants and Values

In computer science, a literal is a notation for representing a fixed value in source code. For example, in the assignment statement. x =…

arrow_forward
description

Python Logical Operators: Combining Conditions in Python

With Logical operators in Python, we can form compound Boolean expressions. Each operand for these logical operators is itself a Boolean…

arrow_forward
description

Python Membership Operators: Testing for Membership in Python

The membership operators in Python help us determine whether an item is present in a given container type object, or in other words,…

arrow_forward
description

Python Method Overloading: Flexible Function Definitions

Method overloading is an important feature of object-oriented programming. Java, C++, C# languages support method overloading, but in…

arrow_forward
description

Python Method Overriding: Customizing Inherited Methods

You can always override your parent class methods. One reason for overriding parent's methods is that you may want special or different…

arrow_forward
description

Python Modules: Organizing Code for Reusability

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for…

arrow_forward
description

Python Numbers: Working with Numeric Data in Python

Most of the times you work with numbers in whatever you do. Obviously, any computer application deals with numbers. Hence, programming…

arrow_forward
description

Python OS File and Directory Methods: Interacting with the File System

The os module provides a big range of useful methods to manipulate files. Most of the useful methods are listed here − Sr.No.…

arrow_forward
description

Python Object-Oriented Programming (OOP) Concepts: Building Robust Software

Python has been an object-oriented language since the time it existed. Due to this, creating and using classes and objects are downright…

arrow_forward
description

Python Objects and Classes: The Building Blocks of OOP

Python is a highly object-oriented language. In Python, each and every element in a Python program is an object of one or the other class.…

arrow_forward
description

Python Operators: A Comprehensive Guide

In Python as well as any programming language, Operators are symbols (sometimes keywords) that are predefined to perform a certain most…

arrow_forward
description

Python PIP: Managing Python Packages and Dependencies

Python's standard library is a large collection of ready-to-use modules and packages. In addition to these packages, a Python programmer…

arrow_forward
description

Python Packages: Organizing and Structuring Code

In Python, module is a Python script with .py extension and contains objects such as classes, functions etc. Packages in Python extend the…

arrow_forward
description

Python Polymorphism: Adaptable Behavior in Object-Oriented Code

The term "polymorphism" refers to a function or method taking different form in different contexts. Since Python is a dynamically typed…

arrow_forward
description

Python Positional Arguments: Orderly Function Parameter Handling

The list of variables declared in the parentheses at the time of defining a function are the formal arguments. A function may be defined…

arrow_forward
description

Python Positional-Only Arguments: Strict Parameter Ordering

It is possible to define a function in which one or more arguments can not accept their value with keywords. Such arguments may be called…

arrow_forward
description

Python Reflection: Introspection and Dynamic Code Exploration

In object-oriented programming, reflection refers to the ability to extract information about any object in use. You can get to know the…

arrow_forward
description

Python Set Exercises: Practice for Set Manipulation

Example 1 Python program to find common elements in two lists with the help of set operations −   l1=[1,2,3,4,5] l2=[4,5,6,7,8]…

arrow_forward
description

Python Set Methods: Efficient Set Operations

Following methods are defined in Python's set class − Sr.No Methods & Description 1 add() Add an element to a set.…

arrow_forward
description

Python Set Operators: Performing Operations on Sets

In the Set Theory of Mathematics, the union, intersection, difference and symmetric difference operations are defined. Python implements…

arrow_forward
description

Python Singleton Class: Ensuring Single Instance Creation

A Singleton class is a class of which only one object can be created. This helps in optimizing memory usage when you perform some heavy…

arrow_forward
description

Python Static Methods: Self-Contained Functions in Classes

is that the static method doesn't have a mandatory argument like reference to the object − self or reference to the class − cls. Python's…

arrow_forward
description

Python String Exercises: Practice for Text Manipulation

Example 1 Python program to find number of vowels in a given string.   mystr = "All animals are equal. Some are more equal" vowels =…

arrow_forward
description

Python String Formatting: Structuring Text Output

String formatting is the process of building a string representation dynamically by inserting the value of numeric expressions in an…

arrow_forward
description

Python String Slicing: Extracting Substrings in Python

In Python, a string is an ordered sequence of Unicode characters. Each character in the string has a unique index in the sequence. The…

arrow_forward
description

Python Syntax Errors: Identifying and Fixing Code Mistakes

Generally, three types of errors appear in a computer program: Syntax errors, logical errors and runtime errors. Syntax errors are the most…

arrow_forward
description

Python Tools and Utilities: Enhancing Productivity and Efficiency

The standard library comes with a number of modules that can be used both as modules and as command-line utilities. The dis Module The…

arrow_forward
description

Python Tuple Methods: Efficient Tuple Operations

Since a tuple in Python is immutable, the tuple class doesn't define methods for adding or removing items. The tuple class defines only two…

arrow_forward
description

Python Type Casting: Converting Data Types

In manufacturing, casting is the process of pouring a liquefied or molten metal into a mold, and letting it cool to obtain the desired…

arrow_forward
description

Python User Input: Gathering Input from Users

Every computer application should have a provision to accept data from the user when it is running. This makes the application interactive.…

arrow_forward
description

Python User-Defined Exceptions: Customizing Error Handling

Python also allows you to create your own exceptions by deriving classes from the standard built-in exceptions. Here is an example that…

arrow_forward
description

Python Variable Scope: Understanding Variable Visibility

A variable in Python is a symbols name to the object in computer's memory. Python works on the concept of namespaces to define the context…

arrow_forward
description

Python Wrapper Classes: Enhancing Data Structures

A function in Python is a first-order object. A function can have another function as its argument and wrap another function definition…

arrow_forward
description

Python for Loop: Iterating Through Sequences in Python

The for loop in Python has the ability to iterate over the items of any sequence, such as a list or a string. Syntax for iterating_var in…

arrow_forward
description

Python forelse Loop: Combining Looping and Conditional Checks

Python supports having an "else" statement associated with a "for" loop statement. If the "else" statement is used with a "for" loop, the…

arrow_forward
description

Python match-case Statement: Pattern Matching in Python

Before its 3.10 version, Python lacked a feature similar to switch-case in C or C++. In Python 3.10, a pattern matching technique called…

arrow_forward
description

Python pass Statement: Placeholder for Future Code

The pass statement is used when a statement is required syntactically but you do not want any command or code to execute. The pass…

arrow_forward
description

Python try-finally Block: Ensuring Cleanup in Exception Handling

You can use a finally: block along with a try: block. The finally: block is a place to put any code that must execute, whether the…

arrow_forward
description

Python while Loop: Iterative Execution in Python

Normally, flow of execution of steps in a computer program goe from start to end. However, instead of the next step, if the flow is…

arrow_forward
description

Python's Versatile Application Domains

Python is a general-purpose programming language. It is suitable for development of wide range of software applications. Over last few…

arrow_forward
description

Raising Exceptions in Python: Triggering Custom Error Conditions

You can raise exceptions in several ways by using the raise statement. The general syntax for the raise statement is as follows − Syntax…

arrow_forward
description

Reading Files in Python: Retrieving Data from External Files

To programmatically read data from a file using Python, it must be opened first. Use the built-in open() function − file object =…

arrow_forward
description

Recursion in Python: Recursive Function Calls for Elegant Solutions

A function that calls itself is called a recursive function. This method is used when a certain problem is defined in terms of itself.…

arrow_forward
description

Regular Expressions in Python: Pattern Matching and Text Manipulation

A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized…

arrow_forward
description

Removing Array Items in Python: Deleting Elements from Arrays

The array class defines two methods with the help of which we can remove an element from the array. It has remove() and pop() methods…

arrow_forward
description

Removing Dictionary Items in Python: Deleting Key-Value Pairs

Using del Keyword Python's del keyword deletes any object from the memory. Here we use it to delete a key-value pair in a dictionary.…

arrow_forward
description

Removing List Items in Python: Deleting Elements from Lists

The list class methods remove() and pop() both can remove an item from a list. The difference between them is that remove() removes the…

arrow_forward
description

Removing Set Items in Python: Deleting Elements from Sets

Python's set class provides different methods to remove one or more items from a set object. remove() Method The remove() method removes…

arrow_forward
description

Renaming and Deleting Files in Python: File Manipulation

Python os module provides methods that help you perform file-processing operations, such as renaming and deleting files. To use this…

arrow_forward
description

Reversing Arrays in Python: Inverting Element Order

In this chapter, we shall explore the different ways to rearrange the given array in the reverse order of the index. In Python, array is…

arrow_forward
description

Sending Email in Python: Automating Email Communication

An application that handles and delivers e-mail over the Internet is called a "mail server". Simple Mail Transfer Protocol (SMTP) is a…

arrow_forward
description

Serialization in Python: Data Serialization and Deserialization

The term "object serialization" refers to process of converting state of an object into byte stream. Once created, this byte stream can…

arrow_forward
description

Setting Up Your Python Development Environment

  First step in the journey of learning Python is to install it on your machine. Today most computer machines, especially having Linux OS,…

arrow_forward
description

Socket Programming in Python: Building Network Communication Solutions

arrow_forward
description

Sorting Arrays in Python: Arranging Elements in Order

Python's array module defines the array class. An object of array class is similar to the array as present in Java or C/C++. Unlike the…

arrow_forward
description

Sorting Lists in Python: Arranging Elements in Order

The sort() method of list class rearranges the items in ascending or descending order with the use of lexicographical ordering mechanism.…

arrow_forward
description

Starting a Thread in Python: Launching Concurrent Execution

This start() method starts the thread's activity. It must be called once a thread object is created. The start() method automatically…

arrow_forward
description

String Concatenation in Python: Combining Text Data

The "+" operator is well-known as an addition operator, returning the sum of two numbers. However, the "+" symbol acts as string…

arrow_forward
description

Synchronizing Threads in Python: Managing Concurrent Access to Shared Resources

The threading module provided with Python includes a simple-to-implement locking mechanism that allows you to synchronize threads. A new…

arrow_forward
description

Templating in Python: Generating Dynamic Content and Documents

Python provides different text formatting features. It including formatting operators, Python's format() function and the f-string. In…

arrow_forward
description

The Main Thread in Python: The Entry Point of Program Execution

Every Python program has at least one thread of execution called the main thread. The main thread by default is a non-daemon thread.…

arrow_forward
description

Thread Deadlock in Python: Handling Resource Deadlocks in Threads

A deadlock may be described as a concurrency failure mode. It is a situation in a program where one or more threads wait for a condition…

arrow_forward
description

Thread Lifecycle in Python: Managing Concurrent Execution

A thread object goes through different stages. When a new thread object is created, it must be started. This calls the run() method of…

arrow_forward
description

Thread Pools in Python: Efficient Management of Thread Resources

What is a Thread Pool? A thread pool is a mechanism that automatically manages a pool of worker threads. Each thread in the pool is called…

arrow_forward
description

Thread Scheduling in Python: Managing Concurrent Execution Order

Python supports multiple threads in a program. A multi-threaded program can execute multiple sub-tasks independently, which allows the…

arrow_forward
description

URL Processing in Python: Handling Web Addresses in Code

In the world of Internet, different resources are identified by URLs (Uniform Resource Locators). The urllib package which is bundled with…

arrow_forward
description

Understanding Python Variables

Python Variables In this tutorial, you will learn what are variables in Python and how to use them. Data items belonging to different…

arrow_forward
description

Understanding the Python Interpreter

Python is an interpreter-based language. In a Linux system, Python's executable is installed in /usr/bin/ directory. For Windows, the…

arrow_forward
description

Unpacking Tuple Items in Python: Extracting Values from Tuples

The term "unpacking" refers to the process of parsing tuple items in individual variables. In Python, the parentheses are the default…

arrow_forward
description

Updating Tuples in Python: Modifying Tuple Elements

In Python, tuple is an immutable data type. An immutable object cannot be modified once it is created in the memory. Example 1 If we try…

arrow_forward
description

Using the break Statement in Python: Breaking Loop Execution

Loop Control Statements The Loop control statements change the execution from its normal sequence. When the execution leaves a scope, all…

arrow_forward
description

Using the if-else Statement in Python: Conditional Execution

Along with the if statement, else keyword can also be optionally used. It provides an alternate block of statements to be executed if the…

arrow_forward
description

Using the try-except Block in Python: Handling Exceptions Gracefully

You can also use the except statement with no exceptions defined as follows − try: You do your operations here ......................…

arrow_forward
description

Weak References in Python: Efficient Memory Management

Python uses reference counting mechanism while implementing garbage collection policy. Whenever an object in the memory is referred, the…

arrow_forward
description

Working with Dictionaries in Python: Key-Value Data Structures

Dictionary is one of the built-in data types in Python. Python's dictionary is example of mapping type. A mapping object 'maps' value of…

arrow_forward
description

Working with Directories in Python: Managing File System Folders

All files are contained within various directories, and Python has no problem handling these too. The os module has several methods that…

arrow_forward
description

Working with Lists in Python: Sequential Data Structures

List is one of the built-in data types in Python. A Python list is a sequence of comma separated items, enclosed in square brackets [ ].…

arrow_forward
description

Working with Nested Dictionaries in Python: Multilevel Key-Value Structures

A Python dictionary is said to have a nested structure if value of one or more keys is another dictionary. A nested dictionary is usually…

arrow_forward
description

Working with Sets in Python: Unordered Collection of Unique Elements

A set is one of the built-in data types in Python. In mathematics, set is a collection of distinct objects. Set data type is Python's…

arrow_forward
description

Working with Strings in Python: Text Manipulation and Processing

In Python, a string is an immutable sequence of Unicode characters. Each character has a unique numeric value as per the UNICODE standard.…

arrow_forward
description

Working with Tuples in Python: Immutable Data Structures"

Tuple is one of the built-in data types in Python. A Python tuple is a sequence of comma separated items, enclosed in parentheses (). The…

arrow_forward
description

Writing to Files in Python: Storing Data in External Files

To write data to a file in Python, you need to open a file. Any object that interacts with input and output steam is called File object.…

arrow_forward
description

XML Processing in Python: Parsing and Manipulating XML Data

XML is a portable, open-source language that allows programmers to develop applications that can be read by other applications, regardless…

arrow_forward
arrow_back « Back