Movatterモバイル変換


[0]ホーム

URL:


2,223 views

Python Programming Essentials - M7 - Strings

Strings in Python are sequences of characters that can be manipulated and accessed using indexes and slicing operations. A string's individual characters can be accessed using indexes like str[0], with negative indexes counting backwards from the end. The length of a string can be found using len(str). Strings are immutable but their values can be reassigned. Strings can be concatenated with + and checked for substrings with the in operator. They support various quote styles and multiline strings using triple quotes.

In this document
Powered by AI

Introduction to Skillbrew and presentation by Pavan Verma on Python Programming Essentials.

A string is defined as a sequence of characters; example: 'Welcome to Python'.

Demonstration of accessing string characters using positive indexes, outputting individual characters.

Illustration of accessing string characters using negative indexes, retrieving characters from the end.

Using the len() function to determine the length of the string, example output is 17.

Explains that single and double quotes can be used interchangeably for string literals.

Shows how to escape quotes within quoted strings using opposite type quotes.

Introduction to triple quotes for multi-line strings, beneficial for long text.

Clarifies that single and double triple quotes function the same; they can be used for docstrings.

Highlights that there is no separate char data type in Python; a character is a string of length 1.

Reiterates that single and double quoted strings are fundamentally the same in Python.

Demonstrates string concatenation using the + operator with examples.

Explains TypeError encountered when concatenating a string with a non-string type.

Shows how to convert non-string types to strings using str() for concatenation.

Describes that strings cannot be modified in place; show TypeErrors for item assignment.

Clarifies that while strings are immutable, variables can point to different strings.

Defines string slicing as a method to extract substrings or parts of the string.

Shows examples of string slicing, including specific index ranges and full string returns.

Outlines key concepts of slicing, stating slices return new strings and describe behavior with indexes.

Explains the 'in' operator for checking substring presence and provides examples.

Summarizes key topics covered: definitions, access methods, quote usage, string operations, immutability.

Provides links to tutorials and references on Python strings for more in-depth learning.

Empty conclusion slide.

Embed presentation

http://www.skillbrew.com/SkillbrewTalent brewed by theindustry itselfStringsPavan VermaPython Programming Essentials@YinYangPavan
© SkillBrew http://skillbrew.comWhat is a String A string is a sequence of charactersmessage = "Welcome to Python"2
© SkillBrew http://skillbrew.comAccess a character in string3message = 'Welcome to Python'print message[0]print message[1]print message[2]print message[3]print message[4]Output:Welcostr[index]
© SkillBrew http://skillbrew.comNegative Indexes4message = 'Welcome to Python'print message[-1]print message[-2]print message[-3]print message[-4]Output:nohtstr[-index]
© SkillBrew http://skillbrew.comLength of a string5message = 'Welcome to Python'print len(message)Output:17len(string)
© SkillBrew http://skillbrew.comSingle quotes Vs Double quotes You can use either single quotes or doublequotes for string literals – they are the same6>>> text = 'some text'>>> text = "some text"
© SkillBrew http://skillbrew.comSingle quotes Vs Double quotes (2) Need to escape double quotes in double quotedstrings• Use single quotes for strings that contain double quotes>>> s = "He said "Hello"">>> s'He said "Hello"' Need to escape single quotes in single quoted strings• Use double quotes for strings that contain single quotes>>> s = 'You've got an error!'>>> s"You've got an error!"7
© SkillBrew http://skillbrew.comTriple quoted strings Python also has triple quoted strings available In some cases, when you need to include really longstring using triple quoted strings is useful>>> message = """This is a multi line messageuse triple quotes if the text is too long"""8
© SkillBrew http://skillbrew.comTriple quoted strings (2) You can also uses triple single quotes, there is nodifference between single triple quoted strings anddouble triple quoted strings>>> message = '''This is a multi line messageuse triple quotes if the text is too long'''9Triple quoted strings are also used as Docstrings which will becovered in functions
© SkillBrew http://skillbrew.comNote for C/C++ Programmers There is no separate char data type in Python In Python, a character is just a string of length 1eg: text ='f'10
© SkillBrew http://skillbrew.comNote for Perl/PHP Programmers Remember that single-quoted strings and double-quoted strings are the same – they do not differ inany significant way11
© SkillBrew http://skillbrew.comString Concatenation12>>> 'foo' + 'bar''foobar'>>> 'foo' + 'bar' + '123''foobar123'>>> name = 'Monty'>>> last_name = 'Python'>>> name + last_name'MontyPython'+ operator is used toconcatenate strings
© SkillBrew http://skillbrew.comString Concatenation (2)13>>> 'foo' + 'bar' + 123TypeError: cannot concatenate 'str' and'int' objectsstring concatenation does not works with other types
© SkillBrew http://skillbrew.comString Concatenation (2)14>>> 'foo' + 'bar' + str(123)'foobar123'Use built in str() function to convert to a string
© SkillBrew http://skillbrew.comStrings are immutable15>>> message = 'Python is awesome'>>> message[0] = 'j'TypeError: 'str' object does not supportitem assignment>>> message = 'Python is awesome'>>> del message[0]TypeError: 'str' object does not supportitem deletion.Python stringscannot be changed
© SkillBrew http://skillbrew.comStrings are immutable (2)16Strings are immutable but that does not mean the variablecannot change, variable can point to anything>>> message = 'Python is awesome'>>> message'Python is awesome'>>> message = 'Python is dynamicalytyped'>>> message'Python is dynamicaly typed'
© SkillBrew http://skillbrew.comWhat is Slicing17slicing in Python is powerful way of extracting sub-parts ofa string, lists, tuplesUse Case:You can use slicing to extract sub-string out of astring
© SkillBrew http://skillbrew.comSlicing18message = 'Python is awesome'print message[0:5]print message[7:10]print message[10:17]print message[:]print message[5:]print message[:6]Outputs:PythoisawesomePython is awesomen is awesomePythonstr[start:end]start: substring starts from this elementend: end of substring excluding the element at this index
© SkillBrew http://skillbrew.comSlicing (2)19str[start:end]1. Slicing always returns a new string. Remember strings areimmutable2. If you don’t provide start the substring starts from the beginningof the string. eg: message[:5]3. If end is not provided the substring runs till the end of thestring4. If both start and end are missing the entire string is returned
© SkillBrew http://skillbrew.comin operatorin is a Boolean operator which takes two stringsand returns True if the first string is a sub-stringof the second string, False otherwise't' in 'Welcome to Python'True'Python' in 'Welcome to Python'True'Python' in 'Welcome to Python'True20
Summary What is a string Access characters in a string Negative indexes Length of string Single quotes Vs Double quotes Triple quoted strings String concatenation Strings are Immutable in operator21
© SkillBrew http://skillbrew.comResources Tutorial on python stringshttp://www.tutorialspoint.com/Python/Python_strings.htm Single vs double stringshttp://docs.ckan.org/en/latest/Python-coding-standards.html22
23

Recommended

PPTX
Python Programming Essentials - M5 - Variables
PPTX
Database connectivity in python
PPTX
Python Programming Essentials - M23 - datetime module
PDF
Python-02| Input, Output & Import
PPTX
Data Structure and Algorithms Merge Sort
PPTX
Estrutura de dados em Java - Pilhas
PPTX
PPTX
Chapter 15 Lists
PPTX
Chapter 14 strings
PPTX
Merge sort
PPTX
Python Programming Essentials - M24 - math module
PDF
Python strings
PPTX
Python strings presentation
PPT
Stacks
PPTX
Selection sort algorithm presentation, selection sort example using power point
PPTX
Max priority queue
PDF
Python 3.x quick syntax guide
PPTX
Python Programming Essentials - M9 - String Formatting
PPTX
Python Programming Essentials - M8 - String Methods
PDF
Debugging of (C)Python applications
PPTX
The scarlet letter
PPTX
Python Programming Essentials - M4 - Editors and IDEs
PPTX
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
PPTX
Python Programming Essentials - M21 - Exception Handling
PPTX
Python Programming Essentials - M1 - Course Introduction
PDF
Web front end development introduction to html css and javascript
PPTX
Python Programming Essentials - M40 - Invoking External Programs
PPTX
Python Programming Essentials - M28 - Debugging with pdb
PPTX
Python Programming Essentials - M31 - PEP 8
PPTX
Python Programming Essentials - M44 - Overview of Web Development

More Related Content

PPTX
Python Programming Essentials - M5 - Variables
PPTX
Database connectivity in python
PPTX
Python Programming Essentials - M23 - datetime module
PDF
Python-02| Input, Output & Import
PPTX
Data Structure and Algorithms Merge Sort
PPTX
Estrutura de dados em Java - Pilhas
PPTX
PPTX
Chapter 15 Lists
Python Programming Essentials - M5 - Variables
Database connectivity in python
Python Programming Essentials - M23 - datetime module
Python-02| Input, Output & Import
Data Structure and Algorithms Merge Sort
Estrutura de dados em Java - Pilhas
Chapter 15 Lists

What's hot

PPTX
Chapter 14 strings
PPTX
Merge sort
PPTX
Python Programming Essentials - M24 - math module
PDF
Python strings
PPTX
Python strings presentation
PPT
Stacks
PPTX
Selection sort algorithm presentation, selection sort example using power point
PPTX
Max priority queue
PDF
Python 3.x quick syntax guide
Chapter 14 strings
Merge sort
Python Programming Essentials - M24 - math module
Python strings
Python strings presentation
Stacks
Selection sort algorithm presentation, selection sort example using power point
Max priority queue
Python 3.x quick syntax guide

Viewers also liked

PPTX
Python Programming Essentials - M9 - String Formatting
PPTX
Python Programming Essentials - M8 - String Methods
PDF
Debugging of (C)Python applications
PPTX
The scarlet letter
PPTX
Python Programming Essentials - M4 - Editors and IDEs
PPTX
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
PPTX
Python Programming Essentials - M21 - Exception Handling
PPTX
Python Programming Essentials - M1 - Course Introduction
PDF
Web front end development introduction to html css and javascript
PPTX
Python Programming Essentials - M40 - Invoking External Programs
PPTX
Python Programming Essentials - M28 - Debugging with pdb
PPTX
Python Programming Essentials - M31 - PEP 8
PPTX
Python Programming Essentials - M44 - Overview of Web Development
PPTX
Using Quotes in Newswriting
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M8 - String Methods
Debugging of (C)Python applications
The scarlet letter
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M1 - Course Introduction
Web front end development introduction to html css and javascript
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M44 - Overview of Web Development
Using Quotes in Newswriting

Similar to Python Programming Essentials - M7 - Strings

PPTX
Python Strings and its Featues Explained in Detail .pptx
PPTX
Practice Python Program-1.pptx
PPTX
Practice Program-1.pptx.
PPTX
Python begginer Practice Program-1.pptx
PDF
python_strings.pdf
PPTX
Python Programming-UNIT-II - Strings.pptx
PDF
strings in python (presentation for DSA)
PPTX
STRINGS IN PYTHON
PPTX
trisha comp ppt.pptx
PPT
PPS_Unit 4.ppt
PPTX
Introduction To Programming with Python-3
PDF
Strings in Python
PDF
Unit 1-Part-3 - String Manipulation.pdf
PPTX
Python Strings.pptx
PPTX
UNIT 4 python.pptx
PDF
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
PPTX
Engineering CS 5th Sem Python Module -2.pptx
PPTX
Python String Revisited.pptx
PPTX
ecFDkQifGYWkHLXQ395.pptxbbbbngvbngrrghxcvvb
PDF
Python data handling
Python Strings and its Featues Explained in Detail .pptx
Practice Python Program-1.pptx
Practice Program-1.pptx.
Python begginer Practice Program-1.pptx
python_strings.pdf
Python Programming-UNIT-II - Strings.pptx
strings in python (presentation for DSA)
STRINGS IN PYTHON
trisha comp ppt.pptx
PPS_Unit 4.ppt
Introduction To Programming with Python-3
Strings in Python
Unit 1-Part-3 - String Manipulation.pdf
Python Strings.pptx
UNIT 4 python.pptx
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
Engineering CS 5th Sem Python Module -2.pptx
Python String Revisited.pptx
ecFDkQifGYWkHLXQ395.pptxbbbbngvbngrrghxcvvb
Python data handling

More from P3 InfoTech Solutions Pvt. Ltd.

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

Recently uploaded

PDF
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
PDF
[DevFest Strasbourg 2025] - NodeJs Can do that !!
PDF
[BDD 2025 - Mobile Development] Mobile Engineer and Software Engineer: Are we...
PPTX
Leon Brands - Intro to GPU Occlusion (Graphics Programming Conference 2024)
PDF
Accessibility & Inclusion: What Comes Next. Presentation of the Digital Acces...
PDF
Top Crypto Supers 15th Report November 2025
PDF
How Much Does It Cost To Build Software
PDF
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
PPTX
"Feelings versus facts: why metrics are more important than intuition", Igor ...
 
PDF
Mastering UiPath Maestro – Session 2 – Building a Live Use Case - Session 2
PDF
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
PDF
Parallel Computing BCS702 Module notes of the vtu college 7th sem 4.pdf
PDF
[BDD 2025 - Full-Stack Development] Agentic AI Architecture: Redefining Syste...
PDF
Agentic Intro and Hands-on: Build your first Coded Agent
PDF
Lets Build a Serverless Function with Kiro
PDF
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
PPTX
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
PDF
Cybersecurity Prevention and Detection: Unit 2
PDF
The Evolving Role of the CEO in the Age of AI
PDF
KMWorld - KM & AI Bring Collectivity, Nostalgia, & Selectivity
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
[DevFest Strasbourg 2025] - NodeJs Can do that !!
[BDD 2025 - Mobile Development] Mobile Engineer and Software Engineer: Are we...
Leon Brands - Intro to GPU Occlusion (Graphics Programming Conference 2024)
Accessibility & Inclusion: What Comes Next. Presentation of the Digital Acces...
Top Crypto Supers 15th Report November 2025
How Much Does It Cost To Build Software
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
"Feelings versus facts: why metrics are more important than intuition", Igor ...
 
Mastering UiPath Maestro – Session 2 – Building a Live Use Case - Session 2
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
Parallel Computing BCS702 Module notes of the vtu college 7th sem 4.pdf
[BDD 2025 - Full-Stack Development] Agentic AI Architecture: Redefining Syste...
Agentic Intro and Hands-on: Build your first Coded Agent
Lets Build a Serverless Function with Kiro
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
Cybersecurity Prevention and Detection: Unit 2
The Evolving Role of the CEO in the Age of AI
KMWorld - KM & AI Bring Collectivity, Nostalgia, & Selectivity

Python Programming Essentials - M7 - Strings

  • 1.
    http://www.skillbrew.com/SkillbrewTalent brewed bytheindustry itselfStringsPavan VermaPython Programming Essentials@YinYangPavan
  • 2.
    © SkillBrew http://skillbrew.comWhatis a String A string is a sequence of charactersmessage = "Welcome to Python"2
  • 3.
    © SkillBrew http://skillbrew.comAccessa character in string3message = 'Welcome to Python'print message[0]print message[1]print message[2]print message[3]print message[4]Output:Welcostr[index]
  • 4.
    © SkillBrew http://skillbrew.comNegativeIndexes4message = 'Welcome to Python'print message[-1]print message[-2]print message[-3]print message[-4]Output:nohtstr[-index]
  • 5.
    © SkillBrew http://skillbrew.comLengthof a string5message = 'Welcome to Python'print len(message)Output:17len(string)
  • 6.
    © SkillBrew http://skillbrew.comSinglequotes Vs Double quotes You can use either single quotes or doublequotes for string literals – they are the same6>>> text = 'some text'>>> text = "some text"
  • 7.
    © SkillBrew http://skillbrew.comSinglequotes Vs Double quotes (2) Need to escape double quotes in double quotedstrings• Use single quotes for strings that contain double quotes>>> s = "He said "Hello"">>> s'He said "Hello"' Need to escape single quotes in single quoted strings• Use double quotes for strings that contain single quotes>>> s = 'You've got an error!'>>> s"You've got an error!"7
  • 8.
    © SkillBrew http://skillbrew.comTriplequoted strings Python also has triple quoted strings available In some cases, when you need to include really longstring using triple quoted strings is useful>>> message = """This is a multi line messageuse triple quotes if the text is too long"""8
  • 9.
    © SkillBrew http://skillbrew.comTriplequoted strings (2) You can also uses triple single quotes, there is nodifference between single triple quoted strings anddouble triple quoted strings>>> message = '''This is a multi line messageuse triple quotes if the text is too long'''9Triple quoted strings are also used as Docstrings which will becovered in functions
  • 10.
    © SkillBrew http://skillbrew.comNotefor C/C++ Programmers There is no separate char data type in Python In Python, a character is just a string of length 1eg: text ='f'10
  • 11.
    © SkillBrew http://skillbrew.comNotefor Perl/PHP Programmers Remember that single-quoted strings and double-quoted strings are the same – they do not differ inany significant way11
  • 12.
    © SkillBrew http://skillbrew.comStringConcatenation12>>> 'foo' + 'bar''foobar'>>> 'foo' + 'bar' + '123''foobar123'>>> name = 'Monty'>>> last_name = 'Python'>>> name + last_name'MontyPython'+ operator is used toconcatenate strings
  • 13.
    © SkillBrew http://skillbrew.comStringConcatenation (2)13>>> 'foo' + 'bar' + 123TypeError: cannot concatenate 'str' and'int' objectsstring concatenation does not works with other types
  • 14.
    © SkillBrew http://skillbrew.comStringConcatenation (2)14>>> 'foo' + 'bar' + str(123)'foobar123'Use built in str() function to convert to a string
  • 15.
    © SkillBrew http://skillbrew.comStringsare immutable15>>> message = 'Python is awesome'>>> message[0] = 'j'TypeError: 'str' object does not supportitem assignment>>> message = 'Python is awesome'>>> del message[0]TypeError: 'str' object does not supportitem deletion.Python stringscannot be changed
  • 16.
    © SkillBrew http://skillbrew.comStringsare immutable (2)16Strings are immutable but that does not mean the variablecannot change, variable can point to anything>>> message = 'Python is awesome'>>> message'Python is awesome'>>> message = 'Python is dynamicalytyped'>>> message'Python is dynamicaly typed'
  • 17.
    © SkillBrew http://skillbrew.comWhatis Slicing17slicing in Python is powerful way of extracting sub-parts ofa string, lists, tuplesUse Case:You can use slicing to extract sub-string out of astring
  • 18.
    © SkillBrew http://skillbrew.comSlicing18message= 'Python is awesome'print message[0:5]print message[7:10]print message[10:17]print message[:]print message[5:]print message[:6]Outputs:PythoisawesomePython is awesomen is awesomePythonstr[start:end]start: substring starts from this elementend: end of substring excluding the element at this index
  • 19.
    © SkillBrew http://skillbrew.comSlicing(2)19str[start:end]1. Slicing always returns a new string. Remember strings areimmutable2. If you don’t provide start the substring starts from the beginningof the string. eg: message[:5]3. If end is not provided the substring runs till the end of thestring4. If both start and end are missing the entire string is returned
  • 20.
    © SkillBrew http://skillbrew.cominoperatorin is a Boolean operator which takes two stringsand returns True if the first string is a sub-stringof the second string, False otherwise't' in 'Welcome to Python'True'Python' in 'Welcome to Python'True'Python' in 'Welcome to Python'True20
  • 21.
    Summary What isa string Access characters in a string Negative indexes Length of string Single quotes Vs Double quotes Triple quoted strings String concatenation Strings are Immutable in operator21
  • 22.
    © SkillBrew http://skillbrew.comResourcesTutorial on python stringshttp://www.tutorialspoint.com/Python/Python_strings.htm Single vs double stringshttp://docs.ckan.org/en/latest/Python-coding-standards.html22
  • 23.

Editor's Notes

  • #17 Since Strings are immutable therefore operations like updating and deleting a string do not work

[8]ページ先頭

©2009-2025 Movatter.jp