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

Split Vs Strip

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

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

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

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

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

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

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

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

2|Page
➢ Strip method:
Syntax: str.strip()

str.strip(): Removes leading and trailing whitespaces (spaces,


tabs, and newline characters).

str.lstrip(): Removes leading (left) whitespaces.

3|Page
str.rstrip(): Removes trailing (right) whitespaces.

4|Page
Str.strip(“ ”): Removes leading and trailing of what is written
between the (“ ”)

Str.rstrip(“ ”): Removes the trailing of what is written between


the (“ ”)
Str.lstrip(“ ”): 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:
string.split(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