We can make use of the urlencode function from urllib.parse module to do a URL encoding.
Let's take a few examples.
Example 1
from urllib.parse import urlencode
product_query_params = {
'product': 'Smart Phone',
'name': "iPhone 15",
'model': 15
}
product_url_encoded_query = urlencode(product_query_params)
print("URL-encoded Query String:", product_url_encoded_query)
Output:
Example 2:
from urllib.parse import urlencode
movie_details_query_data = {
'title': 'Inception',
'year': 2010,
'director': 'Christopher Nolan',
'genre': 'Science Fiction',
'rating': 8.8,
}
url_encoded_movie_details = urlencode(movie_details_query_data)
print(url_encoded_movie_details)
Output:

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- How to change font, apply bold or italic styles, font size in Windows Notepad - HowTos
- Java 8: Get First and Last Date of the Week for Given Date - Java
- How to Connect to AWS Windows EC2 UI Instance from M1 Mac (Updated) - HowTos
- 34: Traverse a List in Reverse Order - 1000+ Python Programming - Python-Programs
- How to convert Python datetime object to a String - Python
- Remove Now Playing icon from macOS Big Sur Menu Bar - MacOS
- How to get UTC (GMT) time using JavaScript - JavaScript
- How to Disable Mac Terminal Bell Sound - MacOS