In Python, a delimiter is a character or sequence of characters used to separate elements within strings or data structures, making it essential for parsing and managing text and data. Delimiters play a crucial role in operations such as splitting strings and reading structured data files. For instance, the split() method uses a specified delimiter to divide a string into a list of substrings, for example, text. split(',') splits a string at each comma. 

Similarly, when working with CSV files, the csv. Reader function utilizes delimiters to parse each line into a list of values, where a comma is commonly used to separate fields. Additionally, the join() method combines a list of strings into a single string, with a chosen delimiter inserted between each element; for instance, ' '.join(words) creates a sentence from a list of words using a space as the delimiter. Delimiters, therefore, are fundamental tools in Python for handling and structuring textual and tabular data, ensuring effective data manipulation and retrieval.

In Python, delimiters are integral for managing and processing data by defining boundaries within strings or files. For example, in parsing logs or configuration files, custom delimiters can be used to handle specific formats. Delimiters also assist in data transformation tasks, such as converting between different file formats, ensuring compatibility and ease of data handling across various applications.

Delimiters in Python With Example

Delimiters in Python With Example

In Python, delimiters are used to split or join strings and manage data formats. Here are several common examples of how delimiters are employed:

1. Splitting Strings

The split() method is used to divide a string into a list of substrings based on a delimiter.

Example:

text = "apple;banana;cherry"
fruits = text.split(';')
print(fruits)

Output:

['apple', 'banana', 'cherry']

Here, the semicolon (;) is the delimiter used to separate each fruit name.

2. Joining Strings

The join() method concatenates elements of a list into a single string using a delimiter between elements.

Example:

words = ["Python", "is", "fun"]
sentence = ' '.join(words)
print(sentence)

Output:

Python is fun

In this example, a space (' ') is the delimiter used to join the words into a sentence.

3. CSV File Parsing

When working with CSV files, delimiters like commas are used to separate values. The csv module can handle such files efficiently.

Example:

import csv

csv_data = """ name,age,city
Alice,30, New York
Bob,25,Los Angeles"""

# Simulating reading from a file
from io import StringIO
file = StringIO(csv_data)

reader = csv.reader(file, delimiter=',')
for row in reader:
    print(row)

Output:

['name,' 'age,' 'city']
['Alice', '30', 'New York']
['Bob', '25', 'Los Angeles']

Here, the comma (,) acts as the delimiter to separate fields in each row.

4. Custom Delimiters

You can use custom delimiters to format strings in various ways.

Example:

data = "2024-07-30|John Doe|Software Engineer"
parts = data.split('|')
print(parts)


Output:

['2024-07-30', 'John Doe,' 'Software Engineer']

In this case, the pipe (|) is the delimiter separating the date, name, and occupation.

Delimiters are versatile tools in Python for managing and manipulating text and data, helping to parse, format, and organize information effectively.

List of Delimiter in Python

In Python, delimiters are characters or sequences used to separate or organize elements within strings and data. They play a crucial role in parsing, formatting, and processing text and structured data. Common delimiters include commas for CSV files, spaces for word separation, and tabs for columns in tab-delimited files.

They help in splitting strings into lists, joining lists into strings, and managing different data formats efficiently. By understanding and using these delimiters effectively, Python developers can handle and manipulate data with greater precision and ease.

Delimiter
Description
Example
Comma (,)
Commonly used to separate items in lists, CSV files, and parameters.
text = "apple,banana,cherry"<br>items = text.split(',')<br>Output: ['apple', 'banana', 'cherry']
Space (' ')
Used to separate words or elements in text.
sentence = "Python is awesome"<br>words = sentence.split(' ')<br>Output: ['Python', 'is', 'awesome']
Semicolon (;)
Often used in CSV files or data formats to separate values.
data = "2024-07-30;John Doe;Software Engineer"<br>parts = data.split(';')<br>Output: ['2024-07-30', 'John Doe', 'Software Engineer']
Tab (\t)
Used to separate columns in tab-delimited files or data.
data = "Name\tAge\tCity"<br>columns = data.split('\t')<br>Output: ['Name', 'Age', 'City']
**Pipe (`
`)**
Used in some text files and custom data formats to separate fields.
Colon (:)
Used to separate keys and values or in time formats.
time = "14:30:00"<br>components = time.split(':')<br>Output: ['14', '30', '00']
Hyphen (-)
Used in date formats, IDs, or to separate parts of strings.
date = "2024-07-30"<br>parts = date.split('-')<br>Output: ['2024', '07', '30']
Slash (/)
Common in date formats, paths, and URLs.
url = "http://example.com/path/to/resource"<br>segments = url.split('/')<br>Output: ['http:,' '', 'example.com,' 'path,' 'to,' 'resource']
Period (.)
Used in file extensions, decimal numbers, and domain names.
filename = "document.txt"<br>name, ext = filename.split('.')<br>Output: ['document,' 'txt']
Double Quotes (")
Used to denote string literals or separate fields in data.
Data = '"John," "Doe," "30"'<br>fields = data.split('","')<br>Output: ['"John",' '"Doe",' '"30"']

Working on Delimeters in Python

Working on Delimeters in Python

In Python, delimiters are characters or sequences used to separate or terminate sections of data, code, or text. They are crucial in various contexts, such as string manipulation, file parsing, and code formatting. Here’s an overview of how delimiters work in different scenarios in Python:

1. String Manipulation

a. Splitting Strings

When you have a string and you want to break it into parts based on a delimiter, you use the split() method.

For example:

text = "apple,banana,cherry"
parts = text.split(",")
print(parts)  # Output: ['apple', 'banana', 'cherry']

Here, the comma , is the delimiter that separates each fruit in the string.

b. Joining Strings

To combine a list of strings into a single string with a delimiter, you use the join() method:

Fruits = ['apple,' 'banana,' 'cherry']
text = ", ".join(fruits)
print(text)  # Output: "apple, banana, cherry"

In this case, "" is the delimiter used to join the list elements.

2. File Parsing

When reading from or writing to files, delimiters help in parsing structured data formats. For example, CSV (Comma-Separated Values) files use commas as delimiters to separate values.

import csv

with open('data.csv', mode='r') as file:
    csv_reader = csv.reader(file, delimiter=',')
    for row in csv_reader:
        print(row)

Here, ',' is the delimiter used by the csv.reader to parse the CSV file.

3. Regular Expressions

Delimiters in regular expressions can be used to specify patterns for matching or splitting strings. For instance, to split a string by any of several delimiters:

import re

text = "apple;banana,orange|grape"
parts = re.split(r'[;,|]', text)
print(parts)  # Output: ['apple', 'banana', 'orange', 'grape']


In this case, the regular expression [;,|] matches any of the characters;, ,, or |, effectively using them as delimiters.

4. String Formatting

When formatting strings with placeholders, delimiters can help in organizing the format. For example, in f-strings or using the format() method, delimiters are used to specify where and how values should be inserted:

name = "Alice"
age = 30
formatted_string = f"Name: {name}, Age: {age}"
print(formatted_string)  # Output: "Name: Alice, Age: 30"


Here, ", " serves as a delimiter between the different pieces of information in the formatted string.

5. Command-Line Arguments

When handling command-line arguments, delimiters can be used to parse options and values. For example, when using argparse:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-n', '--name', type=str, help='Name of the user')
args = parser.parse_args()
print(args.name)

Here, -n or --name acts as a delimiter to specify different options for the command-line arguments.

What is The List Split() Method?

The split() method in Python is a string method used to divide a string into a list of substrings based on a specified delimiter. By default, it separates the string at each whitespace character (such as spaces, tabs, or newlines). You can also provide a custom delimiter as an argument to the split() method, which tells Python where to make the splits.

For example, calling "apple,banana,cherry".split(',') would produce the list ['apple', 'banana', 'cherry']. Additionally, you can limit the number of splits by specifying the maxsplit parameter, which controls how many times the string is divided. If no delimiter is found or the string is empty, the method handles these cases gracefully, returning either a list with the original string or an empty list, respectively.

What is Python String Split Function? 

The Python string split() function is a method used to divide a string into a list of substrings based on a specified delimiter. It is a commonly used function for parsing and manipulating strings.

Syntax

str.split([separator[, maxsplit]])

  • Separator (optional): The delimiter on which to split the string. If not provided, the method uses any whitespace character (space, tab, newline) as the default delimiter.
  • maxsplit (optional): Specifies the maximum number of splits to perform. If not provided or set to -1, the string will be split at all occurrences of the delimiter.

Examples

1. Basic Usage

text = "Hello world"
result = text.split()
print(result)


Output:

['Hello', 'world']


Here, the string is split at each space.

2. Using a Custom Separator

data = "apple,banana,cherry"
result = data.split(',')
print(result)


Output:

['apple', 'banana', 'cherry']


In this example, the string is split at each comma.

3. Limiting the Number of Splits

text = "one two three four"
result = text.split(' ', 2)
print(result)

Output:

['one', 'two', 'three four']


Here, the string is split into a maximum of three parts.

4. No Delimiter Provided

text = "   a b c   "
result = text.split()
print(result)


Output:

['a', 'b', 'c']


When no delimiter is specified, the method splits on any whitespace and ignores extra whitespace.

Syntax of String Split Function in Python

The syntax of the split() method for strings in Python is as follows:

str.split([separator[, maxsplit]])

Parameters

1. separator (optional):

  • The delimiter on which the string is split. It can be any string or character. If not provided, the method defaults to any whitespace character (space, tab, newline, etc.).
  • Example: separator=' ', separator=','

2. maxsplit (optional):

  • An integer that specifies the maximum number of splits to perform. The default value is -1, which means "split all occurrences."
  • Example: maxsplit=2

Returns

  • The method returns a list of substrings.

Examples

1. Basic Usage (Default separator: whitespace)

text = "Hello world"
result = text.split()
print(result)

Output:

['Hello', 'world']


2. Using a Custom Separator

data = "apple,banana,cherry"
result = data.split(',')
print(result)

Output:

['apple', 'banana', 'cherry']


3. Limiting the Number of Splits

text = "one two three four"
result = text.split(' ', 2)
print(result)

Output:

['one', 'two', 'three four']


4. Empty String with No Separator

text = "   a b c   "
result = text.split()
print(result)


Output:

['a', 'b', 'c']

What is the Need For Py Split Function? 

The split() function in Python is crucial for various text-processing tasks. It enables developers to parse and manage strings by dividing them into a list of substrings based on a specified delimiter. This capability is particularly useful for parsing structured data formats, such as CSV files, where commas or other delimiters separate fields.

It also facilitates tokenization in text analysis, allowing the breakdown of sentences into individual words or tokens. Additionally, split() helps in data cleaning by normalizing and removing unwanted whitespace from strings. It is essential for extracting specific pieces of information from structured text, such as date components or URL parts. Overall, the split() function simplifies string manipulation and analysis, making it an indispensable tool in programming.

How to Work With Split Functions in Python? 

The split() function in Python is a powerful tool for dividing strings into lists of substrings based on a specified delimiter. By default, it splits a string at any whitespace, but you can also provide a custom separator to target specific characters or patterns. For example, calling split() on a string like "apple, banana, cherry" with a comma as the delimiter will yield a list of individual fruit names. 

Additionally, the max split parameter allows you to control the number of splits, enabling you to limit how many parts the string is divided into. This function is particularly useful for parsing data, such as CSV files, processing user inputs, or tokenizing text for analysis. It simplifies string manipulation tasks by allowing you to break down and work with text data easily.

Example of Python Split Method

Basic Splitting

Consider you have a string containing several words separated by spaces, and you want to divide this string into a list of individual words.

text = "Python is a versatile language"
words = text.split()
print(words)


Explanation:

  • text.split(): This method call splits the text string at each whitespace (space, tab, or newline) by default.
  • Result: The split() method returns a list of substrings, where each substring is a word from the original string.

Output:

['Python', 'is', 'a', 'versatile', 'language']

In this example, the string "Python is a versatile language" is split into individual words, resulting in a list where each word is an element. This method is particularly useful for tasks such as text analysis, where breaking down sentences into words or tokens is necessary.

What Are Split Parameters in Python?

The parameters for the split() method in Python are:

  • separator (optional): The delimiter string or character to split the string on. Default is any whitespace.
  • maxsplit (optional): The maximum number of splits to perform. Default is -1, which means "split at all occurrences."

How to Parse a String in Python Using the Split() Method?

To parse a string in Python using the split() method, follow these steps:

  • Identify the Delimiter: Determine the character or string that separates the parts of the string you want to extract.
  • Call the split() Method: Use the split() method on the string with the identified delimiter to break it into a list of substrings.
  • Process the Resulting List: Handle or manipulate the list of substrings as needed for your application.

Example

Suppose you have a string containing a comma-separated list of names and ages, and you want to parse this information into separate components:

# Example string
data = "John Doe,30,New York"

# Step 1: Identify the delimiter (comma in this case)

# Step 2: Use the split() method to parse the string
parsed_data = data.split(',')

# Step 3: Process the resulting list
name = parsed_data[0]
age = parsed_data[1]
city = parsed_data[2]

print(f"Name: {name}")
print(f"Age: {age}")
print(f"City: {city}")


Output:

Name: John Doe
Age: 30
City: New York

How to Use the Split() Method With Parameters?

To use the split() method in Python with parameters, follow these steps:

  • Choose the Delimiter (separator): Decide what character or string will be used to split the original string. This is the separator parameter.
  • Set the Maximum Number of Splits (maxsplit): Determine if you want to limit the number of splits. The maxsplit parameter specifies how many times the string should be split. If not provided, the default is -1, meaning no limit.

Syntax

str.split([separator[, maxsplit]])

  • Separator (optional): The delimiter on which to split the string. Defaults to any whitespace if not specified.
  • maxsplit (optional): The maximum number of splits to perform. Defaults to -1 if not specified, which means split at all occurrences.

Examples

1. Using a Custom Separator

text = "apple;banana;cherry"
# Split using ';' as the separator
fruits = text.split(';')
print(fruits)


Output:

['apple', 'banana', 'cherry']


Here, the separator is ';', so the string is split at each semicolon.

2. Limiting the Number of Splits

text = "one two three four"
# Split using ' ' (space) with a maximum of 2 splits
parts = text.split(' ', 2)
print(parts)


Output:

['one', 'two', 'three four']


In this example, the maxsplit parameter is 2, so the string is split into three parts: the first two splits occur at spaces, and the remainder of the string is left as the last part.

3. Using Both Parameters

text = "apple,banana,grape,orange"
# Split using ',' as the separator with a maximum of 2 splits
result = text.split(',', 2)
print(result)


Output:

['apple', 'banana', 'grape,orange']


Here, the string is split at the first two commas, and the rest of the string is left intact.

Applications of Split Function

Applications of Split Function

  • Parsing CSV Data The split() function is used to break down lines of CSV (Comma-Separated Values) data into individual fields. For instance, if you have a line "John,Doe,30,New York", calling split(',') will separate this into ['John', 'Doe', '30', 'New York']. This makes it easy to handle and process each piece of data individually.
  • Tokenizing Text In natural language processing (NLP), tokenization involves splitting a text into individual words or tokens. For example, the sentence "Machine learning is fascinating." can be split into ['Machine', 'learning', 'is', 'fascinating.']. This helps in analyzing the structure and content of the text, which is crucial for tasks like sentiment analysis or text classification.
  • Data Cleaning The split() function aids in cleaning and formatting data by removing extra spaces or unwanted characters. For example, given a string " Hello world ", using split() will remove the extra spaces and produce ['Hello', 'world'], which is more manageable for further processing.
  • Processing User Input When user input is provided in a structured format (e.g., "Jane Smith,25,Los Angeles"), split() can be used to extract and separate different pieces of information. This allows you to handle and utilize user data effectively, such as extracting a name, age, and city from the input string.
  • Parsing Log Files In log file analysis, split() helps break down log entries into their components, such as timestamps, log levels, and messages. For example, a log entry "2024-08-01 12:34:56 ERROR Something went wrong" can be split to extract ['2024-08-01', '12:34:56', 'ERROR', 'Something went wrong'], which helps in analyzing and debugging issues.
  • URL Parsing The split() function can be used to separate a URL into its base and query parameters. For instance, "http://example.com/page?name=John&age=30" can be split into ['http://example.com/page', 'name=John&age=30'], making it easier to handle and process different parts of the URL.
  • Extracting Date Components When working with date strings, split() helps to extract individual components like the year, month, and day. For example, the date "2024-08-01" can be split into ['2024', '08', '01'], which allows you to work with each component separately for tasks such as date formatting or calculations.

What Are the Different Ways of Using the Split Function? 

The split() function in Python is a versatile tool for breaking down strings into lists of substrings based on specified delimiters. By default, it splits by whitespace, but you can customize the separator to handle different delimiters, limit the number of splits, or use regular expressions for more complex scenarios. This functionality is essential for tasks like parsing text, processing user input, and cleaning data.

  • Default Splitting by Whitespace: The split() function, when used without any parameters, divides the string at each whitespace character (spaces, tabs, or newlines). This is useful for breaking down a string into individual words or tokens.
  • Using a Custom Separator: You can specify a custom delimiter (like a comma, semicolon, or any other character) to split the string. This allows you to separate a string based on specific characters or sequences, such as splitting CSV data or text with predefined delimiters.
  • Limiting the Number of Splits: By using the maxsplit parameter, you can control the maximum number of splits to perform. This is helpful when you want to split a string into a limited number of parts and keep the remaining text together as one substring.
  • Splitting with Multiple Delimiters: The split() method can be used in conjunction with regular expressions to handle multiple delimiters. This allows you to split a string by various characters or sequences, such as commas, semicolons, or spaces.
  • Splitting by a Specific Character: You can target a specific character or substring as the delimiter. This is useful for cases where you need to split based on a particular character or pattern that may not be covered by default whitespace or simple delimiters.
  • Handling Empty Strings: When splitting an empty string, the result is an empty list. This behavior is important for handling cases where the input might be empty, ensuring that your code handles such scenarios gracefully.
  • Splitting Lines from a Multi-line String: For multi-line strings, you can split based on newline characters. This allows you to process each line of a text block separately, which is useful for handling text data with multiple lines or entries.
  • Splitting with No Separator: Using split() without specifying any arguments splits the string at any whitespace and discards extra whitespace. This effectively normalizes the spacing in the text, which can be helpful for cleaning up and standardizing text input.

Miscellaneous Tips on Split Function 

The split() function in Python offers flexible ways to divide strings into substrings based on specified delimiters. It's useful for tasks like text processing and data parsing. Understanding tips and best practices, such as handling multiple delimiters and managing performance, can enhance its effectiveness and efficiency in various applications.

  • Handle Consecutive Delimiters: If the string contains consecutive delimiters, split() will produce empty strings for each pair of delimiters. To avoid this, use regular expressions or preprocess the string to handle such cases.
  • Use maxsplit Wisely: When using maxsplit, remember it limits the number of splits but keeps the rest of the string as the last element in the resulting list. This can be useful for splitting only a portion of the string while preserving the remaining data.
  • Whitespace Normalization: When splitting a string by default whitespace, split() automatically removes extra spaces. This is useful for normalizing text with inconsistent spacing.
  • Splitting on Newlines: For multi-line strings, use split('\n') to break the string into lines. This is helpful for processing text files or user inputs with line breaks.
  • Avoid split() on Empty Strings: Splitting an empty string returns an empty list, which should be considered in your code to avoid unexpected results.
  • Be Cautious with Delimiters: Ensure that the delimiter you choose does not occur within the actual data you want to keep intact. Otherwise, you might unintentionally split data incorrectly.
  • Regular Expressions for Complex Delimiters: Use the re.split() function for more complex splitting needs involving multiple delimiters or patterns.
  • Performance Considerations: For large strings or frequent splitting operations, be mindful of performance. Efficient use of split() and appropriate preprocessing can help manage performance impacts.

Uses Cases of Delimeters in Python

Uses Cases of Delimeters in Python

Delimiters are used in a variety of scenarios in Python for managing and organizing data, text, and code. Here’s a detailed look at some common use cases for delimiters:

1. String Parsing and Manipulation

a. Splitting Strings

Delimiters are often used to split a string into parts based on a specific character or sequence. This is useful for parsing text data or extracting information.

text = "one;two;three;four"
parts = text.split(";")
print(parts)  # Output: ['one', 'two', 'three', 'four']

b. Joining Strings

Conversely, delimiters can be used to combine a list of strings into a single string, with the delimiter separating the individual elements.

words = ['apple', 'banana', 'cherry']
sentence = " | ".join(words)
print(sentence)  # Output: "apple | banana | cherry"


2. Reading and Writing Data Files

a. CSV Files

CSV files use commas (or other characters) as delimiters to separate values. The csv module in Python handles these delimiters to read and write data in CSV format.

import csv

# Reading a CSV file
with open('data.csv', mode='r') as file:
    csv_reader = csv.reader(file, delimiter=',')
    for row in csv_reader:
        print(row)

# Writing to a CSV file
with open('data.csv', mode='w', newline='') as file:
    csv_writer = csv.writer(file, delimiter=',')
    csv_writer.writerow(['Name', 'Age', 'City'])
    csv_writer.writerow(['Alice', '30', 'New York'])
    csv_writer.writerow(['Bob', '25', 'Los Angeles'])


b. Tab-Delimited Files

For tab-delimited data, you can specify the tab character as a delimiter.

with open('data.tsv', mode='r') as file:
    tsv_reader = csv.reader(file, delimiter='\t')
    for row in tsv_reader:
        print(row)


3. Regular Expressions

In regular expressions, delimiters are used to define patterns for searching or splitting strings based on complex criteria.

import re

text = "apple;banana|cherry,grape"
parts = re.split(r'[;|,]', text)
print(parts)  # Output: ['apple', 'banana', 'cherry', 'grape']

4. Command-Line Arguments

Command-line arguments often use delimiters to separate options and their values. The argparse module helps parse these arguments.

import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-n', '--name', type=str, help='Name of the user')
parser.add_argument('-a', '--age', type=int, help='Age of the user')
args = parser.parse_args()

print(f"Name: {args.name}")
print(f"Age: {args.age}")

5. Text File Formats

In various text file formats, delimiters define the structure of the data. For example, in INI files, sections are delimited by headers:

[Section1]
key1=value1
key2=value2

[Section2]
keyA=valueA
keyB=valueB


Python’s configparser module can read such files, treating = as the delimiter between keys and values.

from configparser import ConfigParser

config = ConfigParser()
config.read('config.ini')

print(config['Section1']['key1'])  # Output: value1

6. Data Serialization

In data serialization formats like JSON, delimiters help structure the data into key-value pairs.

import json

data = {
    "name": "Alice",
    "age": 30,
    "city": "New York"
}

json_string = json.dumps(data)
print(json_string)  # Output: {"name": "Alice", "age": 30, "city": "New York"}

parsed_data = json.loads(json_string)
print(parsed_data)  # Output: {'name': 'Alice', 'age': 30, 'city': 'New York'}


7. Log Files

Log files often use delimiters to separate fields for better readability and parsing. For instance, log entries might be separated by spaces, tabs, or custom characters.

log_entry = "2024-07-30 12:34:56 INFO ModuleName - Message"
timestamp, level, message = log_entry.split(" ", 2)
print(f"Timestamp: {timestamp}")
print(f"Level: {level}")
print(f"Message: {message}")

Conclusion

Delimiters are fundamental in Python for managing and structuring various types of data. They are pivotal in string manipulation, where they help in splitting and joining text to facilitate data extraction and processing. In file handling, delimiters such as commas in CSV or tabs in TSV files enable structured reading and writing, which is essential for managing large datasets. Regular expressions utilize delimiters to define complex search patterns, allowing precise text manipulations. In command-line interfaces, delimiters parse user inputs and options, making scripts and applications more flexible. 

Configuration files and data serialization formats like JSON use delimiters to organize settings and data structures, streamlining configuration and data exchange. Additionally, delimiters in log files aid in parsing and analyzing log entries, which is crucial for debugging and monitoring. Overall, a deep understanding of delimiters enhances your ability to process and manage data efficiently, leading to more organized and readable code.

FAQ's

👇 Instructions

Copy and paste below code to page Head section

A delimiter is a character or sequence of characters used to separate or define boundaries between different pieces of data within a string or file. It helps in organizing and parsing data.

You can use the split() method of a string to split it by a specific delimiter. For example: text = "apple;banana;cherry" parts = text.split(";") print(parts) # Output: ['apple', 'banana', 'cherry']

Common delimiters in data files include: Commas (,): Used in CSV (Comma-Separated Values) files. Tabs (\t): Used in TSV (Tab-Separated Values) files. Semicolons (;): Sometimes used in CSV files, especially in European locales.

Yes, delimiters can be used in regular expressions to define patterns for searching or splitting text. For example: import re text = "apple;banana|cherry,grape" parts = re.split(r'[;|,]', text) print(parts) # Output: ['apple', 'banana', 'cherry', 'grape']

Delimiters in configuration files, such as =, :, or -, help separate keys and values, sections, or different configuration parameters, making it easier to read and manage settings.

Delimiters in command-line arguments separate options and values. For example, in argparse, you can define options and their delimiters: import argparse parser = argparse.ArgumentParser() parser.add_argument('-n', '--name', type=str, help='Name of the user') parser.add_argument('-a', '--age', type=int, help='Age of the user') args = parser.parse_args() print(f"Name: {args.name}") print(f"Age: {args.age}")

Ready to Master the Skills that Drive Your Career?
Avail your free 1:1 mentorship session.
Thank you! A career counselor will be in touch with you shortly.
Oops! Something went wrong while submitting the form.
Join Our Community and Get Benefits of
💥  Course offers
😎  Newsletters
⚡  Updates and future events
a purple circle with a white arrow pointing to the left
Request Callback
undefined
a phone icon with the letter c on it
We recieved your Response
Will we mail you in few days for more details
undefined
Oops! Something went wrong while submitting the form.
undefined
a green and white icon of a phone
undefined
Ready to Master the Skills that Drive Your Career?
Avail your free 1:1 mentorship session.
Thank you! A career counselor will be in touch with
you shortly.
Oops! Something went wrong while submitting the form.
Get a 1:1 Mentorship call with our Career Advisor
Book free session