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 99 of 855
getpass() 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 MoreHow to print without newline in Python?
In Python, the print() function adds a newline character by default at the end of each output. When you have multiple print statements, each output appears on a separate line. However, you can modify this behavior using the end parameter to print everything on a single line. Normal Print() Behavior By default, each print() statement ends with a newline character (), causing output to appear on separate lines ? Example print("Apple") print("Mango") print("Banana") Output Apple Mango Banana Using the end Parameter The end parameter controls what character(s) ...
Read MoreHow to download Google Images using Python
Google Images can be downloaded programmatically using Python packages that search and fetch images based on keywords. The google_images_download package provides a simple interface to download images by specifying search terms and parameters. Installation First, install the required package using pip ? pip install google_images_download Basic Image Download Here's how to download a limited number of images with URL printing enabled ? from google_images_download import google_images_download # Instantiate the class response = google_images_download.googleimagesdownload() # Set download parameters arguments = { "keywords": "lilly, hills", ...
Read More