Programming Articles

Page 28 of 2547

Print first m multiples of n without using any loop in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 794 Views

In this tutorial, we will write a program to find the first m multiples of a number n without using loops. For example, if n = 4 and m = 3, the output should be 4, 8, 12 (three multiples of four). The main constraint is avoiding loops. We can use the range() function to achieve this without loops. The range() function returns a range object that generates a sequence of numbers. Syntax range(start, stop, step) Parameters start − Starting number of the range stop − Ending number (not included in the ...

Read More

Python program to count occurrences of a word in a string

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will write a program that counts the number of times a word occurs in a string. You are given a word and a string, and we need to calculate the frequency of the word in the string. Suppose we have a string "I am a programmer. I am a student." and the word "am". The program will return 2 as the word occurs two times in the string. Algorithm 1. Initialize the string and the word as two variables. 2. Split the string at spaces using the split() method to get a ...

Read More

Python program to find the IP Address of the client

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 61K+ Views

In this tutorial, we are going to find the IP address of the client using the socket module in Python. Every laptop, mobile, tablet, etc., has their unique IP address. We will find it by using the socket module. Let's see the steps to find out the IP address of a device. Algorithm Import the socket module. Get the hostname using the socket.gethostname() method and store it in a variable. Find the IP address by passing the hostname as an argument to the socket.gethostbyname() method and store it in a variable. Print the IP address. ...

Read More

Sort a list according to the Length of the Elements in Python program

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 6K+ Views

We have a list of strings and our goal is to sort the list based on the length of strings in the list. We have to arrange the strings in ascending order according to their lengths. We can do this using Python built-in method sort() or function sorted() along with a key. Let's take an example to see the output − Input: strings = ["hafeez", "aslan", "honey", "appi"] Output: ["appi", "aslan", "honey", "hafeez"] Using sorted() Function The sorted() function returns a new sorted list without modifying the original list. We pass len as ...

Read More

Reverse words in a given String in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 19K+ Views

We are given a string, and our goal is to reverse all the words which are present in the string. We can use the split() method and reversed() function to achieve this. Let's see some sample test cases. Input: string = "I am a python programmer" Output: programmer python a am I Input: string = "tutorialspoint is a educational website" Output: website educational a is tutorialspoint Python provides multiple approaches to reverse words in a string. Let's explore the most common methods. Method 1: Using split() and reversed() This approach splits ...

Read More

How to run Python code on Google Colaboratory?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 918 Views

Google Colaboratory (Colab) is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. It is hosted in Google Cloud and maintained by Google, allowing Python developers to write, run, and share code using a web browser. In this article, we will learn how to set up and use Google Colab for Python programming. Accessing Google Colab Navigate to the Google Colab website at https://colab.research.google.com/. You'll see the welcome screen with options to create a new notebook or open existing ones from various sources like GitHub, Google Drive, or upload from your computer. ...

Read More

getpass() and getuser() in Python (Password without echo)

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

The getpass module in Python provides secure password input functionality without displaying typed characters on screen. This is essential for applications requiring password authentication where you need to hide sensitive input from shoulder surfing or screen recording. Basic Password Input with getpass() The getpass() function prompts for a password and reads input without echoing it to the terminal ? import getpass try: pwd = getpass.getpass() except Exception as err: print('Error Occurred:', err) else: print('Password entered:', pwd) The output of the above ...

Read More

Few mistakes when using Python dictionary

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 314 Views

Dictionaries in Python are a data structure that maps keys to values as key-value pairs. They are one of the most frequently used data structures and have many useful properties. However, there are several common mistakes developers make when working with dictionaries that can lead to errors or unexpected behavior. Basic Dictionary Operations Before exploring common mistakes, let's review basic dictionary operations ? # Creating a dictionary days_dict = {'day1': 'Mon', 'day2': 'Tue', 'day3': 'Wed'} print(type(days_dict)) print(days_dict) # Using the dict() constructor days_dict2 = dict([('day1', 'Mon'), ('day2', 'Tue'), ('day3', 'Wed')]) print(days_dict2) ...

Read More

Datagram in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 670 Views

User Datagram Protocol (UDP) is a connectionless protocol that allows data transmission between network endpoints without establishing a persistent connection. In UDP communication, data is sent as datagrams — independent packets that contain both the message and addressing information. The sender transmits packets without tracking delivery status, making UDP faster but less reliable than TCP. Understanding UDP Communication UDP communication requires two main components: IP Address: Identifies the target machine on the network Port Number: Specifies which application should receive the data Python's socket module provides the necessary tools to implement UDP communication through ...

Read More

colorsys module in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

The colorsys module in Python allows bidirectional conversions of color values between RGB (Red Green Blue) and other color spaces. The three other color spaces it supports are YIQ (Luminance In-phase Quadrature), HLS (Hue Lightness Saturation), and HSV (Hue Saturation Value). All coordinates range between 0 and 1, except I and Q values in YIQ color space which can range from -1 to 1. Available Functions The colorsys module provides six conversion functions ? Function Purpose Permitted Values rgb_to_yiq Convert RGB coordinates to YIQ coordinates 0 to 1 (RGB), -1 ...

Read More
Showing 271–280 of 25,467 articles
« Prev 1 26 27 28 29 30 2547 Next »
Advertisements