Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 27 of 855
Python program to find the IP Address of the client
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 MoreSort a list according to the Length of the Elements in Python program
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 MoreReverse words in a given String in Python
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 MoreHow to run Python code on Google Colaboratory?
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 Moregetpass() and getuser() in Python (Password without echo)
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 MoreFew mistakes when using Python dictionary
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 MoreDatagram in Python
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 Morecolorsys module in Python
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 MoreFilter in Python
The filter() function in Python creates a new iterator from elements of an iterable for which a function returns True. It's useful for extracting elements that meet specific criteria from lists, tuples, or other sequences. Syntax filter(function, iterable) Parameters: function − A function that returns True or False for each element iterable − Any sequence like list, tuple, set, or string to be filtered Basic Example Let's filter months that have 30 days from a list of months ? # List of months months = ['Jan', 'Feb', 'Mar', 'Apr', ...
Read MoreChange Data Type for one or more columns in Pandas Dataframe
Converting data types of columns in a Pandas DataFrame is essential for data analysis and calculations. Pandas provides several methods to change column data types efficiently. Using astype() The astype() method converts existing columns to specified data types. You can convert all columns or target specific ones ? Converting All Columns to String import pandas as pd # Sample dataframe df = pd.DataFrame({ 'DayNo': [1, 2, 3, 4, 5, 6, 7], 'Name': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 'Qty': [2.6, 5, ...
Read More