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)

Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoiiStrings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
pawankamal3
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Notes3
Notes3Notes3
Notes3
hccit
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
Nicholas I
 
Different uses of String in Python.pptx
Different uses of  String in Python.pptxDifferent uses of  String in Python.pptx
Different uses of String in Python.pptx
AryadipDey
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Python- strings
Python- stringsPython- strings
Python- strings
Krishna Nanda
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
mahendranaik18
 
Biswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptxBiswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptx
BiswambarBehera5
 
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdfpython1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
rohithzach
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Python basics
Python basicsPython basics
Python basics
Luis Goldster
 
Python basics
Python basicsPython basics
Python basics
Tony Nguyen
 
Python basics
Python basicsPython basics
Python basics
Fraboni Ec
 
Python basics
Python basicsPython basics
Python basics
Harry Potter
 
Python basics
Python basicsPython basics
Python basics
Young Alista
 
Python basics
Python basicsPython basics
Python basics
James Wong
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoiiStrings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
pawankamal3
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Notes3
Notes3Notes3
Notes3
hccit
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
Nicholas I
 
Different uses of String in Python.pptx
Different uses of  String in Python.pptxDifferent uses of  String in Python.pptx
Different uses of String in Python.pptx
AryadipDey
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
mahendranaik18
 
Biswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptxBiswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptx
BiswambarBehera5
 
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdfpython1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
rohithzach
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
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)

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
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
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
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.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
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
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
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
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
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
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
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
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
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.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
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
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
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
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
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 

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])