SlideShare a Scribd company logo
USE OF SPLIT() FUNCTION IN STRING
COMPUTER SCIENCE 083
What is split() function?
The split() method breaks up a string at the specified separator.
The syntax of split() is:
String_name_variable. ([separator [, maxsplit]])
Both separator and maxsplit are optional
What is separator?
It is a delimiter. The string splits at the
specified separator.
If the separator is not specified, any
whitespace (space, newline etc.)in a string is
a separator.
What is maxsplit?
It defines the maximum number of splits.
The default value of maxsplit is -1,
meaning, no limit on the number of splits.
How split() works in Python?
take one example:
If We Store a sentence given below in a string variable:
“Welcome to the python”
If we go through the string given below:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
value starts from 0 for first character
But we need to break the words from the s
Use of split() without any separator or
maxsplit:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
If We use only: split()
Example: nm=“Welcome to the python”
print(nm.split())
------output---------
[‘Welcome’,’to’,’the’,’python’]
If the separator is not specified space work as separator
Use of split() with any separator:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e ; t o ; t h e ; p y t h o n
If We use only: split(“;”)
Example: nm=“Welcome;to;the;python”
print(nm.split(“;”))
------output---------
[‘Welcome’,’to’,’the’,’python’]
If the separator is specified its break according to those separator mentioned
Use of split() with any separator and
maxsplit:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e ; t o ; t h e ; p y t h o n
If We use only: split(“;”,2)
Example: nm=“Welcome;to;the;python”
print(nm.split(“;”,2))
------output---------
[‘Welcome’,’to’,’the;python’]
If the separator is specified and maxsplit given then its break according to maxsplit
Let Us learn more about split() use:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
How We use split() and store output in another variable.
Then What happens????
Let us understand with the help of example:
First thing that we need to know:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
That when we declare a variable and store string.
nm=“Welcome to the python”
String character when we want to read
Its read according to index value character by
character.
But what happens when we use method
split():
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
print(nm.split())
nm=“Welcome to the python”
It’s break the words according to the separator,
by default separator is spaces.
[‘Welcome’,’to’,’the’,’python’]
But what happens when we use method
split():
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
[‘Welcome’,’to’,’the’,’python’]
break the words from the string and display output as given below:IT
Now How we access these words that break using
split()
Lets first store the result using split() into
another variable.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
[‘Welcome’,’to’,’the’,’python’]
Now let’s store the string using split() into another variable.
nm=“Welcome to the python”
wstr=nm.split()
Now when we use print() to display wstr
print(wstr)
Now if you want to display words of
your choice.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
If we want to display “the”
Welcome
Example: If we want to display
On the basis of our choice
How we display it.
Word one by oneto the python
First thing is to know what happens to a
string, after we use split() function.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
W e l c o m e t o t h e p y t h o n
Welcome
Before we use split() string looks like as shown below:
After we use split() its break and store as it shown below:
How it is store in memory, if we go through the output.
to the python[ ], , ,wstr=
On the basis of output, it store words
after split() in memory as shown below.
Welcome to the python[ ], , ,
0 1 2 3
Welcome Store at 0 index values
to Store at 1 index values
the Store at 2 index values
python Store at 3 index values
wstr=
If we want to display “c” from the word
“Welcome”.
Welcome
It means the 4th character from the word.
to the python[ ], , ,
0 1 2 3
So Before we move forward let Us understand
Understand how the words store in memory after using
split() logically.
wstr=
How these words store logically.
Welcome
0,1,2,3 are the index values as shown below:
So how we display the character from each word
to the python[ ], , ,
0 1 2 3
Now let us understand with an easy method.
wstr=
So first thing we need to understand
that when we split() the string
Welcome
It is store in a variable as shown below:
To make it more easy to understand
to the python[ ], , ,
0 1 2 3
wstr=
Welcome to the python[ ], , ,
0 1 2 3
To make it more easy to understand
columns
rows 0 1 2 3 4 5 6
0 W e l c o m e
1 t o
2 t h e
3 p y t h o n
So 0 is for first row
So 1 is for Second row
So 2 is for third row
So 3 is for fourth row
wstr=
Welcome to the python[ ], , ,
0 1 2 3
Example: If we want to display “Welcome”
columns
rows 0 1 2 3 4 5 6
0 W e l c o m e
1 t o
2 t h e
3 p y t h o n
So 0 is for first row
So 1 is for Second row
So 2 is for third row
So 3 is for fourth row
wstr=
Welcome
Welcome to the python[ ], , ,
0 1 2 3
Example: If we want to display “c” from a “Welcome”
columns
rows 0 1 2 3 4 5 6
0 W e l c o m e
1 t o
2 t h e
3 p y t h o n
So 0 is for first row
So 1 is for Second row
So 2 is for third row
So 3 is for fourth row
wstr=
Welcome to the python[ ], , ,
0 1 2 3
columnsrows
0 1 2 3 4 5 6
0 W e l c o m e
1 t o
2 t h e
3 p y t h o n
So 0 is for first row
So 1 is for Second row
So 2 is for third row
So 3 is for fourth row
wstr=
So how we display “c” from a “Welcome”
print(wstr[ ]0 )
Welcome
So this part is for
row number.
So if we want to display “c” from the
word “Welcome”
print(wstr[ ]0 )
columns
rows
0 1 2 3 4 5 6
0 W e l c o m e
1 t o
2 t h e
3 p y t h o n
We need row number with column number also.
[ ]3
So the syntax is:
variablename[RowNo][ColNo]
So we add one more [ ] brackets with wstr
So lets take some more examples:
print(wstr[ ][ ])
columns
rows
0 1 2 3 4 5 6
0 W e l c o m e
1 t o
2 t h e
3 p y t h o n
Display “python” first character “p”
Display “the” 3rd character “e”
print(wstr[ ][ ])
3 0
2 2
Ans: p
Ans: e
So you must know that if string is :
“Hello now you know how to use it in python program”
Variable nm store the string given below:
If you use split() wstr=nm.split()
And use print: print(wstr)
----OUTPUT-----
[‘Hello’,’now’,’you’,’know’,’how’,’to’,’use’,’it’,’in’,’python’,’program’]
[‘Hello’,’now’,’you’,’know’,’how’,’to’,’use’,’it’,’in’,’python’,’program’]
So if we want to display ‘use’ from the string then:
print(wstr[6])
use
So if we want to display “k” from the word ‘know’
print(wstr[3][0])

More Related Content

What's hot (20)

Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
NUPOORAWSARMOL
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
Circular queue
Circular queueCircular queue
Circular queue
Lovely Professional University
 
DataFrame in Python Pandas
DataFrame in Python PandasDataFrame in Python Pandas
DataFrame in Python Pandas
Sangita Panchal
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
moazamali28
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
nitamhaske
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
Paras Intotech
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
PREEYANKAV
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
MahendraVusa
 

Similar to String in python use of split method (20)

Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
Lecture 2 java.pdf
Lecture 2 java.pdfLecture 2 java.pdf
Lecture 2 java.pdf
SantoshSurwade2
 
C language sample test
C language sample testC language sample test
C language sample test
Sompal Duhan
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189
Mahmoud Samir Fayed
 
Numpy intro presentation for college.pdf
Numpy intro presentation for college.pdfNumpy intro presentation for college.pdf
Numpy intro presentation for college.pdf
kakkarskrishna22
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
Python- strings
Python- stringsPython- strings
Python- strings
Krishna Nanda
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
HarishParthasarathy4
 
funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)
MdFurquan7
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
shailaja30
 
Pointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxPointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptx
krishna50blogging
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
BG Java EE Course
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
C language sample test
C language sample testC language sample test
C language sample test
Sompal Duhan
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189
Mahmoud Samir Fayed
 
Numpy intro presentation for college.pdf
Numpy intro presentation for college.pdfNumpy intro presentation for college.pdf
Numpy intro presentation for college.pdf
kakkarskrishna22
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)
MdFurquan7
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
shailaja30
 
Pointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxPointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptx
krishna50blogging
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210
Mahmoud Samir Fayed
 
Ad

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
vikram mahendra
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
vikram mahendra
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
vikram mahendra
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
vikram mahendra
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
vikram mahendra
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
Ad

Recently uploaded (20)

Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 

String in python use of split method

  • 1. USE OF SPLIT() FUNCTION IN STRING COMPUTER SCIENCE 083
  • 2. What is split() function? The split() method breaks up a string at the specified separator. The syntax of split() is: String_name_variable. ([separator [, maxsplit]]) Both separator and maxsplit are optional
  • 3. What is separator? It is a delimiter. The string splits at the specified separator. If the separator is not specified, any whitespace (space, newline etc.)in a string is a separator.
  • 4. What is maxsplit? It defines the maximum number of splits. The default value of maxsplit is -1, meaning, no limit on the number of splits.
  • 5. How split() works in Python? take one example: If We Store a sentence given below in a string variable: “Welcome to the python”
  • 6. If we go through the string given below: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n value starts from 0 for first character But we need to break the words from the s
  • 7. Use of split() without any separator or maxsplit: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n If We use only: split() Example: nm=“Welcome to the python” print(nm.split()) ------output--------- [‘Welcome’,’to’,’the’,’python’] If the separator is not specified space work as separator
  • 8. Use of split() with any separator: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e ; t o ; t h e ; p y t h o n If We use only: split(“;”) Example: nm=“Welcome;to;the;python” print(nm.split(“;”)) ------output--------- [‘Welcome’,’to’,’the’,’python’] If the separator is specified its break according to those separator mentioned
  • 9. Use of split() with any separator and maxsplit: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e ; t o ; t h e ; p y t h o n If We use only: split(“;”,2) Example: nm=“Welcome;to;the;python” print(nm.split(“;”,2)) ------output--------- [‘Welcome’,’to’,’the;python’] If the separator is specified and maxsplit given then its break according to maxsplit
  • 10. Let Us learn more about split() use: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n How We use split() and store output in another variable. Then What happens???? Let us understand with the help of example:
  • 11. First thing that we need to know: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n That when we declare a variable and store string. nm=“Welcome to the python” String character when we want to read Its read according to index value character by character.
  • 12. But what happens when we use method split(): 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n print(nm.split()) nm=“Welcome to the python” It’s break the words according to the separator, by default separator is spaces. [‘Welcome’,’to’,’the’,’python’]
  • 13. But what happens when we use method split(): 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n [‘Welcome’,’to’,’the’,’python’] break the words from the string and display output as given below:IT Now How we access these words that break using split()
  • 14. Lets first store the result using split() into another variable. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n [‘Welcome’,’to’,’the’,’python’] Now let’s store the string using split() into another variable. nm=“Welcome to the python” wstr=nm.split() Now when we use print() to display wstr print(wstr)
  • 15. Now if you want to display words of your choice. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n If we want to display “the” Welcome Example: If we want to display On the basis of our choice How we display it. Word one by oneto the python
  • 16. First thing is to know what happens to a string, after we use split() function. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 W e l c o m e t o t h e p y t h o n Welcome Before we use split() string looks like as shown below: After we use split() its break and store as it shown below: How it is store in memory, if we go through the output. to the python[ ], , ,wstr=
  • 17. On the basis of output, it store words after split() in memory as shown below. Welcome to the python[ ], , , 0 1 2 3 Welcome Store at 0 index values to Store at 1 index values the Store at 2 index values python Store at 3 index values wstr=
  • 18. If we want to display “c” from the word “Welcome”. Welcome It means the 4th character from the word. to the python[ ], , , 0 1 2 3 So Before we move forward let Us understand Understand how the words store in memory after using split() logically. wstr=
  • 19. How these words store logically. Welcome 0,1,2,3 are the index values as shown below: So how we display the character from each word to the python[ ], , , 0 1 2 3 Now let us understand with an easy method. wstr=
  • 20. So first thing we need to understand that when we split() the string Welcome It is store in a variable as shown below: To make it more easy to understand to the python[ ], , , 0 1 2 3 wstr=
  • 21. Welcome to the python[ ], , , 0 1 2 3 To make it more easy to understand columns rows 0 1 2 3 4 5 6 0 W e l c o m e 1 t o 2 t h e 3 p y t h o n So 0 is for first row So 1 is for Second row So 2 is for third row So 3 is for fourth row wstr=
  • 22. Welcome to the python[ ], , , 0 1 2 3 Example: If we want to display “Welcome” columns rows 0 1 2 3 4 5 6 0 W e l c o m e 1 t o 2 t h e 3 p y t h o n So 0 is for first row So 1 is for Second row So 2 is for third row So 3 is for fourth row wstr= Welcome
  • 23. Welcome to the python[ ], , , 0 1 2 3 Example: If we want to display “c” from a “Welcome” columns rows 0 1 2 3 4 5 6 0 W e l c o m e 1 t o 2 t h e 3 p y t h o n So 0 is for first row So 1 is for Second row So 2 is for third row So 3 is for fourth row wstr=
  • 24. Welcome to the python[ ], , , 0 1 2 3 columnsrows 0 1 2 3 4 5 6 0 W e l c o m e 1 t o 2 t h e 3 p y t h o n So 0 is for first row So 1 is for Second row So 2 is for third row So 3 is for fourth row wstr= So how we display “c” from a “Welcome” print(wstr[ ]0 ) Welcome So this part is for row number.
  • 25. So if we want to display “c” from the word “Welcome” print(wstr[ ]0 ) columns rows 0 1 2 3 4 5 6 0 W e l c o m e 1 t o 2 t h e 3 p y t h o n We need row number with column number also. [ ]3 So the syntax is: variablename[RowNo][ColNo] So we add one more [ ] brackets with wstr
  • 26. So lets take some more examples: print(wstr[ ][ ]) columns rows 0 1 2 3 4 5 6 0 W e l c o m e 1 t o 2 t h e 3 p y t h o n Display “python” first character “p” Display “the” 3rd character “e” print(wstr[ ][ ]) 3 0 2 2 Ans: p Ans: e
  • 27. So you must know that if string is : “Hello now you know how to use it in python program” Variable nm store the string given below: If you use split() wstr=nm.split() And use print: print(wstr) ----OUTPUT----- [‘Hello’,’now’,’you’,’know’,’how’,’to’,’use’,’it’,’in’,’python’,’program’]
  • 28. [‘Hello’,’now’,’you’,’know’,’how’,’to’,’use’,’it’,’in’,’python’,’program’] So if we want to display ‘use’ from the string then: print(wstr[6]) use So if we want to display “k” from the word ‘know’ print(wstr[3][0])