0% found this document useful (0 votes)
541 views9 pages

Strip vs Split in Python Explained

The document discusses the strip and split string methods in Python. Strip removes leading and trailing whitespace from a string while split breaks a string into substrings based on a specified separator. Strip is used for data cleaning while split is commonly used for parsing text data like CSV files or sentences.

Uploaded by

asilprince0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
541 views9 pages

Strip vs Split in Python Explained

The document discusses the strip and split string methods in Python. Strip removes leading and trailing whitespace from a string while split breaks a string into substrings based on a specified separator. Strip is used for data cleaning while split is commonly used for parsing text data like CSV files or sentences.

Uploaded by

asilprince0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

‫كلية التقنية اإللكترونية طرابلس‬

‫حاكمات دقيقة‬
‫‪Homework‬‬
‫‪Strip vs Split‬‬

‫االسم‪ :‬أصيل عبد الكريم شعبان‬

‫رقم القيد‪192244 :‬‬

‫أستاد المادة‪ :‬أ‪.‬أحمد الناجح‬

‫التاريخ‪21/1/2023 :‬‬

‫‪1|Page‬‬
Contents
➢ Strip method: ....................................................................................................................................... 3
➢ Split method: ........................................................................................................................................ 6
➢ Summary:.............................................................................................................................................. 9

2|Page
➢ Strip method:
Syntax: [Link]()

[Link](): Removes leading and trailing whitespaces (spaces,


tabs, and newline characters).

[Link](): Removes leading (left) whitespaces.

3|Page
[Link](): Removes trailing (right) whitespaces.

4|Page
[Link](“ ”): Removes leading and trailing of what is written
between the (“ ”)

[Link](“ ”): Removes the trailing of what is written between


the (“ ”)
[Link](“ ”): Removes the leading of what is written between
the (“ ”)

5|Page
➢ Split method:
function in Python is a string method that is used to split a string into a list
of substrings based on a specified delimiter.

Syntax:
[Link](separator, maxsplit)

Parameter Description

separator Optional. Specifies the separator to use when splitting the


string. By default any whitespace is a separator

maxsplit Optional. Specifies how many splits to do. Default value is


-1, which is "all occurrences"

Basic split: (Whitespace as Default Separator):

6|Page
• splitting with a custom separator:

7|Page
• Specifying the Maximum Number of Splits:

8|Page
• Splitting Lines in a Multiline String:

➢ Summary:

Strip() Split()
split() is used for breaking is used for breaking a string
Used For: a string into substrings, into substrings, typically
typically based on a based on a specified
specified separator,
Application: For example: The split() method
User Input Validation is commonly used
and data cleaning in when dealing with
text data, such as
files
parsing CSV files or
breaking down
sentences into
individual words.

9|Page

You might also like