GROUP
PRESENTATION
GROUP MEMBERS
╸ xxxxx
╸ xxxxx
╸ xxxxx
╸ xxxxx
╸ xxxxx
2
3
CONTENTS
╸ >>> Introduction
╸ >>> Definition
╸ >>> Creating
╸ >>> Indexing
╸ >>> Slicing
╸ >>> Concatenation
╸ >>> String Formatting
╸ >>> Escape Characters
╸ >>> String Methods
4
INTRODUCTION
Initially when we started of learning about python, we dealt
more with numbers, technically integers;
But, in our real world, we tend to use a lot of sentences
than just numbers.
All these so called sentences are what we call “strings”.
5
DEFINITION
6
ᴓ Python string is the collection of the characters surrounded by single quotes,
double quotes, or triple quotes.
ᴓ The computer does not understand the characters; internally, it stores
manipulated character as the combination of the 0's and 1’s.
ᴓ Unlike some other languages, python doesn’t support char datatype, so strings
can be assumed as a list of char.
ᴓ Each character is encoded in the ASCII or Unicode character. So we can say
that Python strings are also called the collection of Unicode characters.
CREATING A STRING :
7
OUTPUT :
• A string can be used directly into the print statement as well…
• As python has inbuilt ‘str’ datatype, when use the python script to find
database, it outputs as ‘str’
INDEXING IN A STRING
8
• Each element of a string can be accessed and dealt with
separately using the concept of indexing.
• Square brackets can be used to access the elements of a string.
Find the output for the above code snippet ^^^
Again all these are the concept of considering ‘str’ as list of
‘char’.
With this same concept, we can even loop through all the
characters in a particular string.
SLICING OF STRINGS
9
 We can return a range of characters by using the slice syntax / operation
 We need to specify the start index and the end index, separated by a colon, to return the
part of the string
 Remember index values always start from zero (0)
 For Example; OUTPUT
 We can also use the indices to print characters in a particular pattern. We need to add
another value called a step value next to the stop value.
 If required even negative index can be used.
STRING CONCATENATION
╸ To concatenate more than a string, we can simply use + operator
╸ Example ;
10
STRING FORMATTING
• As we know we cannot combine different datatypes, without
typecasting.
• We can use the format() method, it takes passed arguments, formats
them and places them in the string where the placeholders { } are;
• This way, we can take a unlimited number of arguments and place
them in the string accordingly.
• We can number the placeholders for clarity
12
ILLUSTRATION :
OUTPUT :
ESCAPE CHARACTERS
13
 To insert characters that are illegal in a string, use an escape character
 An escape character is a ‘  ‘ backslash followed by the character you want to
insert
 For an example, if you want to use quotations inside a string, the interpreter
will misunderstand and throw an error, Instead use the escape characters just
before the required character to avoid that.
ERROR ;
CORRECTION ;
Some of the common escape characters used are mentioned below ;
14
>>> ’ - to use a single quote
>>> ” - to use a double quote
>>> n - to start in a new line
>>> t - to leave a tab space
>>> b - to do a backspace
>>> ooo - to use a octal value
>>> xhh - to use a hexadecimal value
STRING METHODS
15
Unlike other programming languages, python provides a
huge catalogue of features and inbuilt operations to make
the job easier;
16
 capitalize() – converts the first character to upper case
 upper() – converts a string into upper case
 lower() – converts a string into lower case
 title() – converts the first character of every word to upper case
 strip() – removes all the spaces to the left and right of a string
 startswith() – returns true, if string starts with a specified value
 split() – splits the string at the specified separator and returns a list
 replace() – replaces a specified value with another value
 isalpha() – returns true, if all the characters are alphabets
 isupper() – returns true, if all the characters are in upper case
 islower() - returns true, if all the characters are in lower case
 count() – returns the number of times a specified character occurs
CREDITS and REFERENCES
Special thanks to all the people who made and released these
awesome resources for free:
╸ Presentation template by SlidesCarnival
╸ Photographs by Unsplash
╸ Illustrations by Pixsellz
╸ Images by Google Images
╸ Content by javatpoint.com and w3schools.com
17
We appreciate everyone for
spending your valuable time and
attention … : )
18
THANK YOU !

STRINGS IN PYTHON

  • 1.
  • 2.
    GROUP MEMBERS ╸ xxxxx ╸xxxxx ╸ xxxxx ╸ xxxxx ╸ xxxxx 2
  • 3.
  • 4.
    CONTENTS ╸ >>> Introduction ╸>>> Definition ╸ >>> Creating ╸ >>> Indexing ╸ >>> Slicing ╸ >>> Concatenation ╸ >>> String Formatting ╸ >>> Escape Characters ╸ >>> String Methods 4
  • 5.
    INTRODUCTION Initially when westarted of learning about python, we dealt more with numbers, technically integers; But, in our real world, we tend to use a lot of sentences than just numbers. All these so called sentences are what we call “strings”. 5
  • 6.
    DEFINITION 6 ᴓ Python stringis the collection of the characters surrounded by single quotes, double quotes, or triple quotes. ᴓ The computer does not understand the characters; internally, it stores manipulated character as the combination of the 0's and 1’s. ᴓ Unlike some other languages, python doesn’t support char datatype, so strings can be assumed as a list of char. ᴓ Each character is encoded in the ASCII or Unicode character. So we can say that Python strings are also called the collection of Unicode characters.
  • 7.
    CREATING A STRING: 7 OUTPUT : • A string can be used directly into the print statement as well… • As python has inbuilt ‘str’ datatype, when use the python script to find database, it outputs as ‘str’
  • 8.
    INDEXING IN ASTRING 8 • Each element of a string can be accessed and dealt with separately using the concept of indexing. • Square brackets can be used to access the elements of a string. Find the output for the above code snippet ^^^ Again all these are the concept of considering ‘str’ as list of ‘char’. With this same concept, we can even loop through all the characters in a particular string.
  • 9.
    SLICING OF STRINGS 9 We can return a range of characters by using the slice syntax / operation  We need to specify the start index and the end index, separated by a colon, to return the part of the string  Remember index values always start from zero (0)  For Example; OUTPUT  We can also use the indices to print characters in a particular pattern. We need to add another value called a step value next to the stop value.  If required even negative index can be used.
  • 10.
    STRING CONCATENATION ╸ Toconcatenate more than a string, we can simply use + operator ╸ Example ; 10
  • 11.
    STRING FORMATTING • Aswe know we cannot combine different datatypes, without typecasting. • We can use the format() method, it takes passed arguments, formats them and places them in the string where the placeholders { } are; • This way, we can take a unlimited number of arguments and place them in the string accordingly. • We can number the placeholders for clarity
  • 12.
  • 13.
    ESCAPE CHARACTERS 13  Toinsert characters that are illegal in a string, use an escape character  An escape character is a ‘ ‘ backslash followed by the character you want to insert  For an example, if you want to use quotations inside a string, the interpreter will misunderstand and throw an error, Instead use the escape characters just before the required character to avoid that. ERROR ; CORRECTION ;
  • 14.
    Some of thecommon escape characters used are mentioned below ; 14 >>> ’ - to use a single quote >>> ” - to use a double quote >>> n - to start in a new line >>> t - to leave a tab space >>> b - to do a backspace >>> ooo - to use a octal value >>> xhh - to use a hexadecimal value
  • 15.
    STRING METHODS 15 Unlike otherprogramming languages, python provides a huge catalogue of features and inbuilt operations to make the job easier;
  • 16.
    16  capitalize() –converts the first character to upper case  upper() – converts a string into upper case  lower() – converts a string into lower case  title() – converts the first character of every word to upper case  strip() – removes all the spaces to the left and right of a string  startswith() – returns true, if string starts with a specified value  split() – splits the string at the specified separator and returns a list  replace() – replaces a specified value with another value  isalpha() – returns true, if all the characters are alphabets  isupper() – returns true, if all the characters are in upper case  islower() - returns true, if all the characters are in lower case  count() – returns the number of times a specified character occurs
  • 17.
    CREDITS and REFERENCES Specialthanks to all the people who made and released these awesome resources for free: ╸ Presentation template by SlidesCarnival ╸ Photographs by Unsplash ╸ Illustrations by Pixsellz ╸ Images by Google Images ╸ Content by javatpoint.com and w3schools.com 17
  • 18.
    We appreciate everyonefor spending your valuable time and attention … : ) 18 THANK YOU !