strings in python (presentation for DSA)

MirzaAbdullahTariq 18 views 18 slides Mar 03, 2025
Slide 1
Slide 1 of 18
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18

About This Presentation

strings in python


Slide Content

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 andw3schools.com
17

We appreciate everyone for
spending your valuable time and
attention … : )
18
THANK YOU !
Tags