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
Programming Articles
Page 917 of 2547
Reverse 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 MoreCalculate n + nn + nnn + ? + n(m times) in Python
There are a variety of mathematical series which Python can handle gracefully. One such series involves repeated digits where we take a digit n and create a sequence: n + nn + nnn + ... up to m terms. For example, with n=2 and m=4, we get: 2 + 22 + 222 + 2222 = 2468. Approach We convert the digit to a string and concatenate it repeatedly to form numbers with multiple occurrences of the same digit. Then we sum all these generated numbers ? Example def sum_of_series(n, m): # ...
Read Morehowdoi in Python
The howdoi Python package is a command-line tool that provides instant answers to programming questions directly from Stack Overflow. It saves time by fetching code snippets and solutions without opening a web browser. Installation First, install the howdoi package using pip ? pip install howdoi Basic Usage Use howdoi followed by your programming question to get instant answers ? howdoi create a python list >>> l = [None] * 10 >>> l [None, None, None, None, None, None, None, None, None, None] Common Programming Queries ...
Read More