Python
Python remove Duplicates from a List
A list is a container that contains different Python objects, which could be integers, words,...
Python strip() function is a part of built-in functions available in the Python library. The strip() method removes given characters from start and end of the original string. By default, strip() function removes white spaces from start and end of the string and returns the same string without white spaces.
In this Python tutorial, you will learn:
string.strip([characters])
The Python String strip() will return:
str1 = "Welcome to Guru99!" after_strip = str1.strip()
Output:
Welcome to Guru99!
The Python String strip() function works only on strings and will return an error if used on any other data type like list, tuple, etc.
Example when used on list()
mylist = ["a", "b", "c", "d"] print(mylist.strip())
The above will throw an error :
Traceback (most recent call last): File "teststrip.py", line 2, in <module> print(mylist.strip()) AttributeError: 'list' object has no attribute 'strip'
str1 = "Welcome to Guru99!" after_strip = str1.strip() print(after_strip) str2 = "Welcome to Guru99!" after_strip1 = str2.strip() print(after_strip1)
Output:
Welcome to Guru99! Welcome to Guru99!
str1 = "****Welcome to Guru99!****" after_strip = str1.strip("*") print(after_strip) str2 = "Welcome to Guru99!" after_strip1 = str2.strip("99!") print(after_strip1) str3 = "Welcome to Guru99!" after_strip3 = str3.strip("to") print(after_strip3)
Output:
Welcome to Guru99! Welcome to Guru Welcome to Guru99!
Here, are reasons for using Python strip function
A list is a container that contains different Python objects, which could be integers, words,...
In this tutorial of difference between Python and JavaScript, we will discuss the key differences...
What is a Variable in Python? A Python variable is a reserved memory location to store values. In other...
What is Regular Expression in Python? A Regular Expression (RE) in a programming language is a...
What is Python Queue? A queue is a container that holds data. The data that is entered first will...
In Python everything is object and string are an object too. Python string can be created simply...