Movatterモバイル変換


[0]ホーム

URL:


1,911 views

Python Programming Essentials - M8 - String Methods

This document discusses various string methods in Python including upper(), lower(), capitalize(), startswith(), endswith(), strip(), split(), and join(). It provides examples of how to use each method, such as converting strings to uppercase and lowercase, checking if a string starts or ends with certain text, stripping leading and trailing characters, and splitting or joining strings.

In this document
Powered by AI

This slide introduces the presentation topic focusing on common string methods in Python.

A list of common string methods in Python such as upper(), lower(), capitalize(), etc.

Details on upper(), lower(), and capitalize() methods with examples and outputs.

Explanation of the startswith() method, checking if a string starts with a specified text.

Describes startswith() method with optional begin and end parameters for boundary checking.

More examples for startswith() usage demonstrating the method's functionality.

Overview of the endswith() method, indicating if a string ends with specified text.

Covers the strip() method, which removes leading and trailing characters from a string.

Details on lstrip() method, which removes leading characters from a string.

Examines rstrip() method for removing trailing characters from a string.

Introduction to splitting and joining strings as key manipulation techniques.

Describes split() method which converts a string into a list of words.

Further explanation on using split() with a specified delimiter.

Explains join() method that combines elements of a list into a single string.

Examples of joining string elements from a tuple using a specified delimiter.

A practical example of manipulating a URL string using splitting and joining.

First step in the example to split the URL and query string.

Second step in the example focusing on splitting query string parameters.

Updating query parameters and joining them into a new query string.

Final step of joining the updated URL and query string.

Recap of all discussed string methods including upper, startswith, and splitting.

Provides resources such as Python documentation for string methods.

Completion of the presentation, indicating the end of the content.

Embed presentation

http://www.skillbrew.com/SkillbrewTalent brewed by theindustry itselfCommon String MethodsPavan VermaPython Programming Essentials@YinYangPavan
© SkillBrew http://skillbrew.comCommon String Methods upper() lower() capitalize() startswith() endswith() strip() find() split() join()2
© SkillBrew http://skillbrew.comupper, lower, capitalize3message = "enter the dragon"print message.upper()print message.lower()print message.capitalize()Outputs:ENTER THE DRAGONenter the dragonEnter the dragonupper(): Converts alllowercase letters in string touppercaselower(): Converts alluppercase letters in string tolowercasecapitalize():Capitalizes first letter ofstring
© SkillBrew http://skillbrew.comstartswith4startswith(text)• Checks whether the string starts with text• Return’s True if there is a match otherwise False>>> str = "explicit is better than implicit">>> str.startswith('explicit')True>>> str.startswith('Explicit')False>>>
© SkillBrew http://skillbrew.comstartswith (2)5str.startswith(text, begin, end)startswith()optionally takes two arguments begin andend• text − This is the string to be checked• begin − This is the optional parameter to set start index ofthe matching boundary• end − This is the optional parameter to set start index ofthe matching boundary
© SkillBrew http://skillbrew.comstartswith (3)6str = "explicit is better than implicit“>>> print str.startswith("is", 9)True>>> print str.startswith("better", 12, 18)Truestartswith()returns True if matching string found elseFalse
© SkillBrew http://skillbrew.comendswith7>>> str = "explicit is better than implicit">>> str.endswith("implicit")True>>> str.endswith("implicit", 20)True>>> str.endswith("implicit", 25)False>>> str.endswith("than", 19, 23)Trueendswith(text)works the same way as startswith differencebeing it checks whether the string ends with text or not
© SkillBrew http://skillbrew.commessage = " enter the dragon "print message.strip()Output:enter the dragonmessage = "--enter the dragon--"print message.strip(‘-’)Output:enter the dragonstrip(chars):• returns a copy of thestring with leading andtrailing charactersremoved• If chars is omittedor None, whitespacecharacters areremovedstrip8
© SkillBrew http://skillbrew.commessage = " enter the dragon "message.lstrip()Output:'enter the dragon'message = "--enter the dragon--"message.lstrip('-')Output:'enter the dragon--'lstrip(chars):• returns a copy of thestring with leadingcharacters removed• If chars is omittedor None, whitespacecharacters areremovedlstrip9
© SkillBrew http://skillbrew.commessage = " enter the dragon "message.rstrip()Output:' enter the dragon'message = "--enter the dragon--"message.rstrip('-')Output:'--enter the dragon'rstrip(chars):• returns a copy of thestring with trailingcharacters removed• If chars is omittedor None, whitespacecharacters areremovedrstrip10
11SPLITTING AND JOININGSTRINGS
© SkillBrew http://skillbrew.comSplitting12message = "enter the dragon"print message.split()Output:['enter', 'the', 'dragon']split()returns a list of words of the string
© SkillBrew http://skillbrew.comSplitting (2)13message = "enter-the-dragon"print message.split('-')Output:['enter', 'the', 'dragon']split(delimiter)delimiter: character or characters which we want touse to split the string, by default it will be space
© SkillBrew http://skillbrew.comJoining14seq_list = ['enter', 'the', 'dragon']print ''.join(seq_list)Output:enter the dragonstr.join()returns a string in which the string elements of sequence havebeen joined by str separator
© SkillBrew http://skillbrew.comJoining (2)15seq_tuple = ('enter','the','dragon')print '-'.join(seq_tuple)Output:enter-the-dragon
© SkillBrew http://skillbrew.comsplitting/joining example16Lets say you have a link'foo.com/forum?filter=comments&num=20'1. You have to separate out the querystring fromurl2. You have to then separate out key-value pairs inquerystring3. Now update the filter to views and num to 15and form the url again
© SkillBrew http://skillbrew.comsplitting/joining example (2)17>>> link = 'foo.com/forum?filter=comments&num=20'>>> components = link.split('?')>>> components['foo.com/forum', 'filter=comments&num=20']>>> url = components[0]>>> qs = components[1]>>> url'foo.com/forum'>>> qs'filter=comments&num=20'Step 1Split the link using '?' asdelimiter to separate outurl and querystring
© SkillBrew http://skillbrew.comsplitting/joining example (3)18>>> qs'filter=comments&num=20'>>>params = qs.split('&')>>> params['filter=comments', 'num=20']Step 2Split the querystringusing '&' as delimiter
© SkillBrew http://skillbrew.comsplitting/joining example (4)19>>> params['filter=comments', 'num=20']>>> params[0] = 'filter=views'>>> params[1] = 'num=15'>>> params['filter=views', 'num=15']>>> qs = '&'.join(params)>>> qs'filter=views&num=15'Step 3Update the parameters andjoin them using '&' asdelimiter to formquerystring
© SkillBrew http://skillbrew.comsplitting/joining example (5)20>>> url'foo.com/forum'>>> qs'filter=views&num=15'>>> '?'.join([url, qs])'foo.com/forum?filter=views&num=15'>>> link = '?'.join([url, qs])>>> link'foo.com/forum?filter=views&num=15'Step 4join url and querystringusing '?' as delimiter
Summary upper, lower, capitalize startswith and endswith strip, lstrip and rstrip splitting and joining strings21
© SkillBrew http://skillbrew.comResources String methods python docshttp://docs.Python.org/2/library/stdtypes.html#string-methods22
23

Recommended

PDF
Python strings
PPTX
Chapter 05 classes and objects
PPS
String and string buffer
PPTX
Strings in Java
PPS
Wrapper class
PPTX
STRINGS IN PYTHON
PPTX
Python-Inheritance.pptx
PDF
Tuples in Python
PDF
Python programming : Files
PDF
Python programming : Strings
PDF
Strings in Python
PDF
Set methods in python
PPTX
Functions in Python
PPTX
Classes, objects in JAVA
PPTX
Datastructures in python
 
PPTX
String Manipulation in Python
PPTX
Python Functions
PPTX
Python strings presentation
PPTX
Python-Functions.pptx
PPTX
String Builder & String Buffer (Java Programming)
PDF
Python tuple
PDF
Python lambda functions with filter, map & reduce function
PDF
What is Python Lambda Function? Python Tutorial | Edureka
PDF
Php array
PDF
Python functions
PPTX
Introduction to numpy
PDF
JAVA PROGRAMMING - The Collections Framework
PPTX
Function template
PPTX
Python Programming Essentials - M31 - PEP 8
PPTX
Python Programming Essentials - M9 - String Formatting

More Related Content

PDF
Python strings
PPTX
Chapter 05 classes and objects
PPS
String and string buffer
PPTX
Strings in Java
PPS
Wrapper class
PPTX
STRINGS IN PYTHON
PPTX
Python-Inheritance.pptx
PDF
Tuples in Python
Python strings
Chapter 05 classes and objects
String and string buffer
Strings in Java
Wrapper class
STRINGS IN PYTHON
Python-Inheritance.pptx
Tuples in Python

What's hot

PDF
Python programming : Files
PDF
Python programming : Strings
PDF
Strings in Python
PDF
Set methods in python
PPTX
Functions in Python
PPTX
Classes, objects in JAVA
PPTX
Datastructures in python
 
PPTX
String Manipulation in Python
PPTX
Python Functions
PPTX
Python strings presentation
PPTX
Python-Functions.pptx
PPTX
String Builder & String Buffer (Java Programming)
PDF
Python tuple
PDF
Python lambda functions with filter, map & reduce function
PDF
What is Python Lambda Function? Python Tutorial | Edureka
PDF
Php array
PDF
Python functions
PPTX
Introduction to numpy
PDF
JAVA PROGRAMMING - The Collections Framework
PPTX
Function template
Python programming : Files
Python programming : Strings
Strings in Python
Set methods in python
Functions in Python
Classes, objects in JAVA
Datastructures in python
 
String Manipulation in Python
Python Functions
Python strings presentation
Python-Functions.pptx
String Builder & String Buffer (Java Programming)
Python tuple
Python lambda functions with filter, map & reduce function
What is Python Lambda Function? Python Tutorial | Edureka
Php array
Python functions
Introduction to numpy
JAVA PROGRAMMING - The Collections Framework
Function template

Viewers also liked

PPTX
Python Programming Essentials - M31 - PEP 8
PPTX
Python Programming Essentials - M9 - String Formatting
PPTX
Python Programming Essentials - M7 - Strings
PPTX
Python Programming Essentials - M23 - datetime module
PPTX
Python Programming Essentials - M20 - Classes and Objects
PPTX
Python Programming Essentials - M21 - Exception Handling
PDF
Why I Love Python V2
 
PPTX
Python Programming Essentials - M44 - Overview of Web Development
PPTX
Python Programming Essentials - M4 - Editors and IDEs
PPTX
Python Programming Essentials - M1 - Course Introduction
PPTX
Python Programming Essentials - M40 - Invoking External Programs
PPTX
Python Programming Essentials - M28 - Debugging with pdb
PPTX
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M21 - Exception Handling
Why I Love Python V2
 
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M1 - Course Introduction
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M10 - Numbers and Artihmetic Operators

Similar to Python Programming Essentials - M8 - String Methods

PPTX
Python Strings.pptx
PPTX
string manipulation in python ppt for grade 11 cbse
PPTX
stringggg.pptxtujd7ttttttttttttttttttttttttttttttttttt
PPTX
UNIT 4 python.pptx
PPTX
Day5 String python language for btech.pptx
PDF
Python- strings
PDF
Python data handling
PDF
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
PPTX
Python Programming-UNIT-II - Strings.pptx
PPTX
Python Strings and strings types with Examples
PDF
14-Strings-In-Python strings with oops .pdf
PDF
strings in python (presentation for DSA)
PDF
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
PPTX
Python Strings and its Featues Explained in Detail .pptx
PDF
python_strings.pdf
PPTX
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
PPTX
Strings.pptxbfffffffffffffffffffffffffffffffffffffffffd
PDF
PPTX
Introduction To Programming with Python-3
PPT
Strings.ppt
Python Strings.pptx
string manipulation in python ppt for grade 11 cbse
stringggg.pptxtujd7ttttttttttttttttttttttttttttttttttt
UNIT 4 python.pptx
Day5 String python language for btech.pptx
Python- strings
Python data handling
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
Python Programming-UNIT-II - Strings.pptx
Python Strings and strings types with Examples
14-Strings-In-Python strings with oops .pdf
strings in python (presentation for DSA)
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
Python Strings and its Featues Explained in Detail .pptx
python_strings.pdf
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
Strings.pptxbfffffffffffffffffffffffffffffffffffffffffd
Introduction To Programming with Python-3
Strings.ppt

More from P3 InfoTech Solutions Pvt. Ltd.

PPTX
Python Programming Essentials - M25 - os and sys modules
PPTX
Python Programming Essentials - M6 - Code Blocks and Indentation
PPTX
Python Programming Essentials - M5 - Variables
PPTX
Python Programming Essentials - M24 - math module
PPTX
Python Programming Essentials - M27 - Logging module
PPTX
Python Programming Essentials - M29 - Python Interpreter and Files
PPTX
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
PPTX
Python Programming Essentials - M11 - Comparison and Logical Operators
PPTX
Python Programming Essentials - M22 - File Operations
PPTX
Python Programming Essentials - M35 - Iterators & Generators
PPTX
Python Programming Essentials - M13 - Tuples
PPTX
Python Programming Essentials - M18 - Modules and Packages
PPTX
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
PPTX
Python Programming Essentials - M34 - List Comprehensions
PPTX
Python Programming Essentials - M17 - Functions
PPTX
Python Programming Essentials - M12 - Lists
PPTX
Python Programming Essentials - M14 - Dictionaries
PPTX
Python Programming Essentials - M39 - Unit Testing
PPTX
Python Programming Essentials - M15 - References
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M5 - Variables
Python Programming Essentials - M24 - math module
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M15 - References

Recently uploaded

PDF
PCCC25(設立25年記念PCクラスタシンポジウム):エヌビディア合同会社 テーマ2「NVIDIA BlueField-4 DPU」
PDF
[BDD 2025 - Mobile Development] Mobile Engineer and Software Engineer: Are we...
PPTX
MuleSoft AI Series : Introduction to MCP
PDF
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
PDF
Transcript: The partnership effect: Libraries and publishers on collaborating...
PDF
The partnership effect: Libraries and publishers on collaborating and thrivin...
PDF
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
PDF
Open Source Post-Quantum Cryptography - Matt Caswell
PDF
10 Best Automation QA Testing Software Tools in 2025.pdf
PDF
Mulesoft Meetup Online Portuguese: MCP e IA
PDF
Mastering UiPath Maestro – Session 2 – Building a Live Use Case - Session 2
PDF
Top Crypto Supers 15th Report November 2025
PDF
How Much Does It Cost to Build an eCommerce Website in 2025.pdf
PDF
KMWorld - KM & AI Bring Collectivity, Nostalgia, & Selectivity
PDF
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
PDF
Cybersecurity Prevention and Detection: Unit 2
PDF
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
PPTX
kernel PPT (Explanation of Windows Kernal).pptx
PDF
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
PDF
How Much Does It Cost To Build Software
PCCC25(設立25年記念PCクラスタシンポジウム):エヌビディア合同会社 テーマ2「NVIDIA BlueField-4 DPU」
[BDD 2025 - Mobile Development] Mobile Engineer and Software Engineer: Are we...
MuleSoft AI Series : Introduction to MCP
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
Transcript: The partnership effect: Libraries and publishers on collaborating...
The partnership effect: Libraries and publishers on collaborating and thrivin...
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
Open Source Post-Quantum Cryptography - Matt Caswell
10 Best Automation QA Testing Software Tools in 2025.pdf
Mulesoft Meetup Online Portuguese: MCP e IA
Mastering UiPath Maestro – Session 2 – Building a Live Use Case - Session 2
Top Crypto Supers 15th Report November 2025
How Much Does It Cost to Build an eCommerce Website in 2025.pdf
KMWorld - KM & AI Bring Collectivity, Nostalgia, & Selectivity
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
Cybersecurity Prevention and Detection: Unit 2
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
kernel PPT (Explanation of Windows Kernal).pptx
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
How Much Does It Cost To Build Software

Python Programming Essentials - M8 - String Methods

  • 1.
    http://www.skillbrew.com/SkillbrewTalent brewed bytheindustry itselfCommon String MethodsPavan VermaPython Programming Essentials@YinYangPavan
  • 2.
    © SkillBrew http://skillbrew.comCommonString Methods upper() lower() capitalize() startswith() endswith() strip() find() split() join()2
  • 3.
    © SkillBrew http://skillbrew.comupper,lower, capitalize3message = "enter the dragon"print message.upper()print message.lower()print message.capitalize()Outputs:ENTER THE DRAGONenter the dragonEnter the dragonupper(): Converts alllowercase letters in string touppercaselower(): Converts alluppercase letters in string tolowercasecapitalize():Capitalizes first letter ofstring
  • 4.
    © SkillBrew http://skillbrew.comstartswith4startswith(text)•Checks whether the string starts with text• Return’s True if there is a match otherwise False>>> str = "explicit is better than implicit">>> str.startswith('explicit')True>>> str.startswith('Explicit')False>>>
  • 5.
    © SkillBrew http://skillbrew.comstartswith(2)5str.startswith(text, begin, end)startswith()optionally takes two arguments begin andend• text − This is the string to be checked• begin − This is the optional parameter to set start index ofthe matching boundary• end − This is the optional parameter to set start index ofthe matching boundary
  • 6.
    © SkillBrew http://skillbrew.comstartswith(3)6str = "explicit is better than implicit“>>> print str.startswith("is", 9)True>>> print str.startswith("better", 12, 18)Truestartswith()returns True if matching string found elseFalse
  • 7.
    © SkillBrew http://skillbrew.comendswith7>>>str = "explicit is better than implicit">>> str.endswith("implicit")True>>> str.endswith("implicit", 20)True>>> str.endswith("implicit", 25)False>>> str.endswith("than", 19, 23)Trueendswith(text)works the same way as startswith differencebeing it checks whether the string ends with text or not
  • 8.
    © SkillBrew http://skillbrew.commessage= " enter the dragon "print message.strip()Output:enter the dragonmessage = "--enter the dragon--"print message.strip(‘-’)Output:enter the dragonstrip(chars):• returns a copy of thestring with leading andtrailing charactersremoved• If chars is omittedor None, whitespacecharacters areremovedstrip8
  • 9.
    © SkillBrew http://skillbrew.commessage= " enter the dragon "message.lstrip()Output:'enter the dragon'message = "--enter the dragon--"message.lstrip('-')Output:'enter the dragon--'lstrip(chars):• returns a copy of thestring with leadingcharacters removed• If chars is omittedor None, whitespacecharacters areremovedlstrip9
  • 10.
    © SkillBrew http://skillbrew.commessage= " enter the dragon "message.rstrip()Output:' enter the dragon'message = "--enter the dragon--"message.rstrip('-')Output:'--enter the dragon'rstrip(chars):• returns a copy of thestring with trailingcharacters removed• If chars is omittedor None, whitespacecharacters areremovedrstrip10
  • 11.
  • 12.
    © SkillBrew http://skillbrew.comSplitting12message= "enter the dragon"print message.split()Output:['enter', 'the', 'dragon']split()returns a list of words of the string
  • 13.
    © SkillBrew http://skillbrew.comSplitting(2)13message = "enter-the-dragon"print message.split('-')Output:['enter', 'the', 'dragon']split(delimiter)delimiter: character or characters which we want touse to split the string, by default it will be space
  • 14.
    © SkillBrew http://skillbrew.comJoining14seq_list= ['enter', 'the', 'dragon']print ''.join(seq_list)Output:enter the dragonstr.join()returns a string in which the string elements of sequence havebeen joined by str separator
  • 15.
    © SkillBrew http://skillbrew.comJoining(2)15seq_tuple = ('enter','the','dragon')print '-'.join(seq_tuple)Output:enter-the-dragon
  • 16.
    © SkillBrew http://skillbrew.comsplitting/joiningexample16Lets say you have a link'foo.com/forum?filter=comments&num=20'1. You have to separate out the querystring fromurl2. You have to then separate out key-value pairs inquerystring3. Now update the filter to views and num to 15and form the url again
  • 17.
    © SkillBrew http://skillbrew.comsplitting/joiningexample (2)17>>> link = 'foo.com/forum?filter=comments&num=20'>>> components = link.split('?')>>> components['foo.com/forum', 'filter=comments&num=20']>>> url = components[0]>>> qs = components[1]>>> url'foo.com/forum'>>> qs'filter=comments&num=20'Step 1Split the link using '?' asdelimiter to separate outurl and querystring
  • 18.
    © SkillBrew http://skillbrew.comsplitting/joiningexample (3)18>>> qs'filter=comments&num=20'>>>params = qs.split('&')>>> params['filter=comments', 'num=20']Step 2Split the querystringusing '&' as delimiter
  • 19.
    © SkillBrew http://skillbrew.comsplitting/joiningexample (4)19>>> params['filter=comments', 'num=20']>>> params[0] = 'filter=views'>>> params[1] = 'num=15'>>> params['filter=views', 'num=15']>>> qs = '&'.join(params)>>> qs'filter=views&num=15'Step 3Update the parameters andjoin them using '&' asdelimiter to formquerystring
  • 20.
    © SkillBrew http://skillbrew.comsplitting/joiningexample (5)20>>> url'foo.com/forum'>>> qs'filter=views&num=15'>>> '?'.join([url, qs])'foo.com/forum?filter=views&num=15'>>> link = '?'.join([url, qs])>>> link'foo.com/forum?filter=views&num=15'Step 4join url and querystringusing '?' as delimiter
  • 21.
    Summary upper, lower,capitalize startswith and endswith strip, lstrip and rstrip splitting and joining strings21
  • 22.
    © SkillBrew http://skillbrew.comResourcesString methods python docshttp://docs.Python.org/2/library/stdtypes.html#string-methods22
  • 23.

[8]ページ先頭

©2009-2025 Movatter.jp