Python Articles

Page 169 of 855

What are some good Python examples for beginners?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 401 Views

This article provides essential Python examples for beginners, covering data structures, basic operations, and commonly asked interview questions. These examples demonstrate fundamental concepts that form the building blocks of Python programming. Converting a List to a Tuple Using the Python tuple() function, you can convert a list to a tuple. After conversion, the data becomes immutable since tuples cannot be modified ? # input list inputList = ['hello', 'tutorialspoint', 'python', 'codes'] # converting input list into a tuple resultTuple = tuple(inputList) # printing the resultant tuple print(resultTuple) ...

Read More

Is the Python platform independent?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 7K+ Views

Python is a high-level, interpreted programming language that offers platform independence, meaning the same code can run on different operating systems without modification. This cross-platform capability makes Python highly versatile for modern software development. What is Platform Independence? Platform independence refers to the ability of software to run on multiple operating systems without requiring changes to the source code. This feature eliminates the need to write separate versions of the same program for different platforms. Platform independence is classified into two types: Binary Platform Independence − Compiled code can run on different platforms using a ...

Read More

How do you code a vending machine in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 9K+ Views

In this article, we will learn to code a vending machine in Python. A vending machine program simulates the functionality of a real vending machine where users can select items, view their cart, and get a bill. Project Structure Our vending machine will have the following components ? Items Data: A list of dictionaries containing product information Shopping Cart: A list to store selected items Menu Display: Function to show available items Purchase Logic: Handle item selection and validation Bill Generation: Calculate total and display receipt Setting Up Items Data First, we define ...

Read More

How do I read a .data file in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 9K+ Views

In this article, we will learn what is a .data file and how to read a .data file in Python. What is a .data file? .data files are generic data files used to store information in various formats. Data in this format is frequently stored as comma-separated values (CSV), tab-separated values (TSV), or other structured formats. The file may be in binary or text format, which determines how we need to access it. For this tutorial, we will work with both text and binary .data files. Identifying Data Format .data files can contain either text ...

Read More

Can I get a job with a Python certificate?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 1K+ Views

Python certification can definitely help you land a job, especially when combined with practical skills and project experience. Python's versatility across multiple domains makes it one of the most valuable programming languages to master in today's job market. What is Python? Python is a high-level, object-oriented, dynamic, and interpreted programming language that supports multiple programming paradigms. Python's clean syntax, dynamic typing, and interpreted nature make it an excellent choice for beginners and professionals alike. It supports object-oriented, functional, and procedural programming styles, making it incredibly versatile for various applications from web development to artificial intelligence. Why Python ...

Read More

Sorting an array in waveform using Python

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 763 Views

In this article, we will learn how to sort an array in waveform using Python. A waveform array follows the pattern where arr[0] >= arr[1] = arr[3] = ..., creating alternating peaks and valleys. What is Waveform Sorting? An array is sorted in wave form if elements alternate between being greater than or equal to their neighbors. For example, [4, 3, 12, 6, 25, 15] forms a wave pattern where 4 > 3 < 12 > 6 < 25 > 15. Method 1: Using Built-in sort() Function This approach first sorts the array, then swaps adjacent ...

Read More

Sort the matrix row-wise and column-wise using Python

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 2K+ Views

In this article, we will learn how to sort a matrix both row-wise and column-wise using Python. This technique involves sorting rows first, then transposing the matrix to convert columns into rows, sorting again, and transposing back. We'll implement a solution using nested for loops and matrix transposition to achieve both row-wise and column-wise sorting of an MxM matrix. Algorithm Following are the steps to sort a matrix row-wise and column-wise − Create a function sortingMatrixByRow() to sort each row of the matrix using bubble sort. Create a function transposeMatrix() to swap rows and columns ...

Read More

Remove list elements larger than a specific value using Python

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 8K+ Views

When working with lists in Python, you often need to remove elements that exceed a certain threshold. Python offers several approaches to filter out elements larger than a specific value. Methods Overview The following methods can be used to remove elements larger than a specific value ? Using remove() Method (with caution) Using List Comprehension Using filter() Method with Lambda Function Using For Loop with append() Using remove() Method Warning: The remove() method can skip elements when modifying a list during iteration. Here's the problematic approach ? # This approach has ...

Read More

Remove leading zeros from a Number given as a string using Python

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 12K+ Views

In this article, we will learn how to remove leading zeros from a number given as a string using Python. Leading zeros are unnecessary zeros at the beginning of a number that don't affect its mathematical value. We'll explore three effective methods: using lstrip(), regular expressions, and the int() function. Each approach has its own advantages depending on your specific use case. Method 1: Using lstrip() Function The lstrip() method removes specified characters from the beginning of a string. This is the most straightforward approach for removing leading zeros ? def remove_leading_zeros(input_string): ...

Read More

Python program to print matrix in a snake pattern

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 3K+ Views

In this article, we will learn how to print a matrix in a snake pattern. A snake pattern prints the first row left to right, the second row right to left, the third row left to right, and so on, creating a zigzag or snake-like traversal. We will explore two different approaches to accomplish this task using Python. What is a Snake Pattern? Given a matrix, the snake pattern traversal means: Print even-indexed rows (0, 2, 4...) from left to right Print odd-indexed rows (1, 3, 5...) from right to left For example, a ...

Read More
Showing 1681–1690 of 8,549 articles
« Prev 1 167 168 169 170 171 855 Next »
Advertisements