Python String - removeprefix() function Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Python String removeprefix() function removes the prefix and returns the rest of the string. If the prefix string is not found, then it returns the original string.Example: Python s1 = 'Geeks'.removeprefix("Gee") print(s1) Output:ksLet's take a deeper look at removeprefix():Table of ContentSyntax:Example of removeprefix() methodPractical Applications of removeprefix()Syntax:string.removeprefix(prefix)Parameters:string: The original string from which the prefix will be removed.prefix: The substring you want to remove from the start of the string.Return Type: The method returns a new string with the specified prefix removed, if it exists. If the string does not start with the given prefix, it simply returns the original string.Example of removeprefix() methodWe can remove a prefix string from a string using Python String removeprefix() Method. If the prefix is not the prefix in the string, the original string is returned. Python # Basic Usage s = "HelloWorld" res = s.removeprefix("Hello") print(res) # Output: World # No Prefix Match s = "PythonProgramming" res = s.removeprefix("Java") print(res) # Output: PythonProgramming # Case Sensitivity s = "PythonProgramming" res = s.removeprefix("python") print(res) # Output: PythonProgramming Output:WorldPythonProgrammingPythonProgrammingExplanation:string "HelloWorld" has the prefix "Hello", so it removes it and returns "World".Since the string doesn't start with "Java", the original string is returned unchanged.The method is case-sensitive, so it does not remove "python" (lowercase) from "PythonProgramming" because the prefix "python" does not match the case of the actual string's prefix "Python".Practical Applications of removeprefix()Cleaning Data: When processing files or strings with standard prefixes (like file paths, URLs, or formatted strings), removeprefix() can be used to cleanly remove unwanted prefixes.Processing URLs: In web scraping or web applications, you may need to strip a common domain prefix or protocol (http://, https://) from URLs.Automating String Parsing: In scenarios where strings are prefixed with specific identifiers, such as command-line arguments or data fields, removeprefix() can be helpful to automate the parsing.Processing Version Numbers: If version numbers are prefixed with a specific string (e.g., "v" for versions), removeprefix() can be used to extract just the version number.Code Example: Python # Cleaning Data p1 = "/home/user/documents/file.txt" p2 = p1.removeprefix("/home/user/") print(p2) # Output: documents/file.txt # Removing URL Prefix url1 = "https://example.com/" url2 = url.removeprefix("https://") print(url2) # Output: example.com # Parsing Command-Line Arguments c = "cmd-12345" id1 = "cmd-" id2 = c.removeprefix(id1) print(id2) # Output: 12345 # Removing Version Prefix v1 = "v1.2.3" v2 = v1.removeprefix("v") print(v2) # Output: 1.2.3 Output:documents/file.txtexample.com123451.2.3 Comment More info M MuskanKalra1 Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2020 Python-string-functions Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 7 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 6 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like