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
Server Side Programming Articles
Page 551 of 2109
struct module in Python
The struct module in Python converts native Python data types into strings of bytes and vice versa. It's a built-in module that uses C-style format characters to specify data types and their binary representation. Format Characters The struct module uses format characters similar to C language data types ? Data Type Format Character Description int i 4-byte signed integer char c 1-byte character string s char[] (requires length prefix) float f 4-byte floating point struct.pack() - Converting to Bytes The struct.pack() method converts ...
Read Morestring.whitespace in Python
In this tutorial, we are going to learn about string.whitespace in Python. The string.whitespace constant is pre-defined in the string module and contains all ASCII whitespace characters: space, tab, linefeed, return, formfeed, and vertical tab. What is string.whitespace? The string.whitespace is a string constant that contains all characters considered as whitespace in ASCII. This includes: Space character (' ') Tab character ('\t') Newline character ('') Carriage return ('\r') Form feed ('\f') Vertical tab ('\v') Basic Example Let's see what string.whitespace contains ? import string print("Content of string.whitespace:") print(repr(string.whitespace)) print("Length:", len(string.whitespace)) ...
Read Morestring.punctuation in Python
In this tutorial, we are going to learn about the string.punctuation constant in Python. The string.punctuation is a pre-defined string constant in Python's string module that contains all ASCII punctuation characters. We can use it for text processing, password generation, and data validation. What is string.punctuation? The string.punctuation constant contains all printable ASCII punctuation characters as a single string ? import string # Display the punctuation string print("Punctuation characters:") print(string.punctuation) print(f"Total characters: {len(string.punctuation)}") Punctuation characters: !"#$%&'()*+, -./:;?@[\]^_`{|}~ Total characters: 32 Practical Examples Removing Punctuation from Text Remove all ...
Read Morestring.octdigits in Python
In this tutorial, we are going to learn about the string.octdigits constant in Python. The string.octdigits is a pre-defined string constant in the string module of Python. It contains all the octal digits (0-7) as a single string. We can use this constant whenever we need to work with octal digits in our program by simply importing it from the string module. Basic Usage Let's see what string.octdigits contains ? import string # Print the octal digits string print(string.octdigits) print("Length:", len(string.octdigits)) 01234567 Length: 8 Checking the Data Type ...
Read MoreSQL using Python
In this tutorial, we are going to learn how to use SQL with Python using SQLite database. Python has a built-in module to connect with SQLite database. We are going to use sqlite3 module to connect Python and SQLite. We have to follow the below steps to connect the SQLite database with Python ? Import the sqlite3 module. Create a connection using the sqlite3.connect(db_name) method that takes a database name as an argument. It creates one file if it doesn't exist with the given name else it opens the file with ...
Read MoreSplit a string in equal parts (grouper in Python)
In this tutorial, we will learn how to split a string into equal-sized parts using Python. This technique is often called a "grouper" function and is useful for processing data in chunks. Problem Overview Given a string and a desired chunk size, we want to divide the string into equal parts. If the string length is not evenly divisible, we'll pad the last chunk with a fill character. Example 1 Split 'Tutorialspoint' into chunks of 5 characters ? string = 'Tutorialspoint' each_part_length = 5 print(f"Input: '{string}' with chunk size {each_part_length}") Input: ...
Read MoreSet update() in Python to do union of n arrays
In this tutorial, we will use the set.update() method to find the union of multiple arrays. This method efficiently combines arrays while automatically removing duplicates, returning a one-dimensional array with all unique values. What is set.update()? The update() method adds elements from an iterable (like a list or array) to an existing set. It automatically handles duplicates by keeping only unique values. Syntax set.update(iterable) Example Let's see how to union multiple arrays using set.update() ? # initializing the arrays arrays = [[1, 2, 3, 4, 5], [6, 7, 8, 1, ...
Read MoreSend SMS updates to mobile phone using python
In this tutorial, we are going to learn how to send SMS messages in Python using the Twilio API service. Twilio provides a simple and reliable way to send SMS messages programmatically. Setting Up Twilio Account First, go to Twilio and create an account. You will get a free trial account with some credits to test SMS functionality. Complete the account setup and verify your phone number. Installation Install the twilio module using pip ? pip install twilio Getting Twilio Credentials From your Twilio Console Dashboard, you need to collect ? ...
Read Moreself in Python class
In this tutorial, we are going to learn about self in Python classes. The self parameter is a reference to the current instance of a class and is used to access variables and methods belonging to that instance. Note − self is not a keyword in Python. What is self? We use self in classes to represent the instance of an object. We can create multiple instances of a class and each instance will have different values. The self parameter helps us access those property values within the class instance. Basic Example Let's see how ...
Read MoreCalculate difference between adjacent elements in given list using Python
Calculating the difference between adjacent elements in a list is a common task in data analysis. Python provides several efficient approaches to solve this problem using list comprehension, loops, or built-in functions. Problem Definition Given a list, we need to calculate the difference between each adjacent pair of elements (next element minus current element). The result will have one fewer element than the original list. Example Scenario Input: [10, 15, 12, 18] Output: [5, -3, 6] Explanation: 15 - 10 = 5 12 - 15 = -3 18 - 12 = 6 ...
Read More