SlideShare a Scribd company logo
1 of 66
CHAPTER 14
STRINGS
Unit 2:
Computational Thinking and Programming
XI
Computer Science (083)
Board : CBSE
Courtesy CBSE
Unit II
Computational Thinking and Programming
(60 Theory periods 45 Practical Periods)
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)
Department of Computer Science, Sainik School Amaravathinagar
Cell No: 9431453730
Praveen M Jigajinni
Prepared by
Courtesy CBSE
STRINGS
Like many other popular
programming languages, strings in
Python are arrays of bytes representing
Unicode characters. However, Python does
not have a character data type, a single
character is simply a string with a length of
1. Square brackets can be used to access
elements of the string.
STRINGS
How to change or delete a string?
Strings are immutable. This
means that elements of a string cannot be
changed once it has been assigned. We can
simply reassign different strings to the
same name.
>>> my_string = 'programiz'
>>> my_string[5] = 'a'
TypeError: 'str' object does not support
item assignment.
How to change or delete a string?
How to create a string in Python?
How to create a string in Python?
Strings can be created by enclosing
characters inside a single quote or double
quotes. Even triple quotes can be used in
Python but generally used to represent
multiline strings and docstrings.
STRINGS
REPRESENTATION OF STRING
REPRESENTATION OF STRING
>>> s = “Hello Python”
This is how Python would index the string:
Forward Indexing
Backward Indexing
STRINGS – Programming Example
STRINGS - Example
Output Next Slide...
STRINGS - Example
How to access characters in a string?
How to access characters in a string?
We can access individual characters
using indexing and a range of characters
using slicing. Index starts from 0. Trying to
access a character out of index range will
raise an IndexError. The index must be an
integer. We can't use float or other types,
this will result into TypeError.
STRINGS
How to access characters in a string?
Python allows negative indexing for
its sequences.
The index of -1 refers to the last item,
-2 to the second last item and so on. We
can access a range of items in a string by
using the slicing operator (colon).
STRINGS
STRINGS – Programming Example
STRINGS
STRINGS
SLICING STRINGS EXAMPLES
For example:
>>>“Program”[3:5]
will result in:
‘gr ’
>>>“Program”[3:6]
will yield:
‘gra’
>>>p = “Program”
>>>p [:4]
‘Prog’
>>>p = “Program”
>>>p [4:]
‘ram’
>>>p = “Program”
>>>p [3:6]
‘gra’
Index Error!
STRINGS –Index error
More Functionality of String
More Functionality of String
>>> len(“Sainik School”)
13
>>>print(“Sainik” + “School”)
Sainik School
>>>print(“A” * 4 )
AAAA
>>>”sa” in “sainik”
True
>>>”pr” in “computer”
False
Finding Length of string
String Concatenation
String Repeat
Substring Tests
More Functionality of String
>>> name1="computer"
>>> name2=name1[3:5]
>>>name2
pu String Slicing
String Methods
String Methods
In Python, a method is a function that is
defined with respect to a particular object.
Syntax:
object.method(arguments)
For Example:
>>>name=“Classic”
>>>name.find(“s”)
3
the first position
where “s” appears
String object String Method Method Argument
Built in Methods
1. capitalize() Method
Capitalizes first letter of string
First letter capitalization
2. lstrip() & 3. rstrip() Methods
lstrip() method is used to remove left
padded spaces in a given string
>>>name1=“ a “
>>>name1.lstrip()
‘a ‘
rstrip() method is used to remove right
padded spaces in a given string
>>>name1.rstrip()
‘ a’
Removing left spaces
Removing right spaces
4. strip() Method
strip() method is used to remove left
and right padded spaces in a given string
>>>name1=“ a “
>>>name1.strip()
‘a‘
Removing left and right spaces for a given string
5. lower() Method
lower() method is used to convert
given string in to lower case.
>>>name1=“ SAINIK “
>>>name1.lower()
sainik
Converting in to lower case
6. upper() Method
upper() method is used to convert
given string in to upper case.
>>>name1=“ sainik “
>>>name1.upper()
SAINIK
Converting in to upper case
7. title() Method
title() method is used to convert given
string in to title case. Every first chatacter of
word of a given string is converted to title
case.
>>>name1=“ praveen murigeppa jigajinni“
>>>name1.title()
Praveen Murigeppa Jigajinni
In every word first letter is capitalized
8. swapcase() Method
swapcase() method is toggle the case.
Meaining upper to lower and lower to upper
case.
>>>name1=“ PrAvEeN“
>>>name1.swapcase()
pRaVeEn
Every character case is changed
9. ljust() Method
ljust() method is used to add spaces to
the left side of the given string
>>>name1=“ Jigajinni“
>>>name1.ljust(15)
‘Jigajinni ’
Left side padded with spaces
Note: string length is 9 and 6 spaces
added to the left side of string
10. rjust() Method
rjust() method is used to add spaces to
the right side of the given string
>>>name1=“ Jigajinni“
>>>name1.rjust(15)
‘ Jigajinni’
Right side padded with spaces
Note: string length is 9 and 6 spaces
added to the right side of string
11. center(width, fillchar) Method
The method center() returns centered
in a string of length width. Padding is done
using the specified fillchar. Default filler is a
space.
Centered string
12. zfill() Method
zfill() method is used to fill the zero to
a given string
>>>name1=“ 123“
>>>name1.zfill(15)
‘00123 ’
Filling Zeros
13. find() Method
find() method is used to find a
perticular character or string in a given
string.
>>> name1="praveen"
>>> name1.find("e")
4
e is present at 4th location (first appearance)
in a given string
14. count() Method
count() method is used to the number
of times character or string appears in a
given string.
>>>name1=“praveen“
>>>name1.count(“e”)
2
2 times e appears in a given string
15. stratswith() Method
startswith() method is used check
string start with particular string or not
>>>name1=“praveen“
>>>name1.startswith(“a”)
False
Given string not starting with “a”
16. endswith() Method
endswith() method is used check string
ends with particular string or not
>>>name1=“praveen“
>>>name1.endswith(“en”)
True
Given string ends with “en”
17. isdigit() Method
isdigit() method is used check string is
digit (number) or not and returns Boolean
value true or false.
>>>name2=“123”
>>>name2.isdigit()
True
>>name1=“123keyboard“
>>name1.isdigit()
False
Given string not number so false
Given string is
number
18. isnumeric() Method
isnumeric() is similar to isdigit()
method and is used check string is digit
(number) or not and returns Boolean value
true or false.
>>>name2=“123”
>>>name2.isnumeric()
True
>>name1=“123keyboard“
>>name1.isnumeric()
False
Given string not number so false
Given string is
number
19. isdecimal() Method
isnumeric(),isdigit() and isdecimal()
methods are used to check string is digit
(number) or not and returns Boolean value
true or false.
>>>name2=“123”
>>>name2.decimal()
True
>>name1=“123keyboard“
>>name1.isnumeric()
False
Given string not number so false
Given string is
number
20. isalpha() Method
isalpha() method is used check string is
digit or not and returns Boolean value true or
false.
>>>name2=“123”
>>>name2.isalpha()
False
>>name1=“123computer“
>>name1.isalpha()
False
>>>name3=“Keynoard”
>>>Name3.isaplpha()
True
Given string not
string it contains
digits
Given string does
not contain string
It’s a string
21. isalnum() Method
isalnum() method is used check string is
alpha numeric string or not.
>>>name2=“123”
>>>name2.isalnum()
True
>>>name1=“123computer“
>>>name1.isalnum()
True
>>>name3=“Praveen”
>>>name3.isalnum()
True
Given string is
alpha numeric
22. islower() Method
islower() method is used check string
contains all lower case letters or not, it returns
true or false result.
>>>name2=“Praveen”
>>>name2.islower()
False
>>>name1=“praveen“
>>>name1.islower()
True
Given string is not
lower case string
Given string is
lower case string
23. isupper() Method
isupper() method is used check string
contains all letters upper case or not, it returns
true or false result.
>>>name2=“Praveen”
>>>name2.isupper()
False
>>>name1=“PRAVEEN“
>>>name1.isupper()
True
Given string is not
upper case string
Given string is
upper case string
24. isspace() Method
isspace() method is used check string
contains space only or not.
>>>name2=“ ”
>>>name2.isspace()
True
>>>name1=“PRAVEEN M J“
>>>name1.isspace()
False
Given string
contains space only
Given string not
containing space only
25. find() Methods
find() method is used to find a
particular string (substring) in a given
string.
>>>name=“Classic”
>>>name.find(“s”)
3
the first position
where “s” appears
String object String Method Method Argument
26. str() Method
str() method is used convert non
string data into string type.
>>>str(576)
‘576’
576 is number converted to string
27 len() Method
len() method is used get a length of
string.
>>>len(“Praveen”)
7
Gives the string length
28 max() Method
max() method is used get a max
alphabet of string.
>>>max(“Praveen”)
v
Gives max character
29 min() Method
min() method is used get a max
alphabet of string.
>>>min(“Praveen”)
P
Gives min character P because it has
ASCII Value 65
30 split() Method
split() method is used split a string.
Split in to several words or substrings
30 split() Method
split() method is used split a string
according to delimiter.
Split in to several words or substrings
according to delimiter
31 index() Method
Same as find(), but raises an
exception if str not found.
>>> name="Sainik“
>>> name.index("a",3,5)
ValueError: substring not found
>>> name.index("a",1,5)
1 Value error
Character found, returning the position
Character Methods
32. ord() Method
ord() method is used get a ASCII
value for a character.
>>ord(“a”)
97
97 is the ASCII value for character ‘a’
33. chr() Method
char() method is used get a
character for an ASCII value.
>>chr(97)
‘a’
‘a’ ASCII value is 97
Class Test
Class Test
Time: 40 Min Max Marks: 20
1. What is string? 02
2. What is forward indexing and back
word indexing? 03
3. Explain any 5 string built in methods
10
4. What are character methods? Explain
in detail 05
Thank You

More Related Content

What's hot

Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in pythonRaginiJain21
 
python Function
python Function python Function
python Function Ronak Rathi
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python FundamentalsPraveen M Jigajinni
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaEdureka!
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
 
Data types in python
Data types in pythonData types in python
Data types in pythonRaginiJain21
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With PythonPraveen M Jigajinni
 

What's hot (20)

Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Chapter 17 Tuples
Chapter 17 TuplesChapter 17 Tuples
Chapter 17 Tuples
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Python basics
Python basicsPython basics
Python basics
 
python Function
python Function python Function
python Function
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python strings
Python stringsPython strings
Python strings
 
Data types in python
Data types in pythonData types in python
Data types in python
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With Python
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 

Similar to Chapter 14 strings

Chapter 11 Strings.pptx
Chapter 11 Strings.pptxChapter 11 Strings.pptx
Chapter 11 Strings.pptxafsheenfaiq2
 
Detailed description of Strings in Python
Detailed description of Strings in PythonDetailed description of Strings in Python
Detailed description of Strings in PythonKeerthiraja11
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfpaijitk
 
Array assignment
Array assignmentArray assignment
Array assignmentAhmad Kamal
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdfGaneshRaghu4
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1Giovanni Della Lunga
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings MethodsMr Examples
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processingmaznabili
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdfDarellMuchoko
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arraysphanleson
 

Similar to Chapter 14 strings (20)

Chapter 11 Strings.pptx
Chapter 11 Strings.pptxChapter 11 Strings.pptx
Chapter 11 Strings.pptx
 
Detailed description of Strings in Python
Detailed description of Strings in PythonDetailed description of Strings in Python
Detailed description of Strings in Python
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
Array assignment
Array assignmentArray assignment
Array assignment
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
Python String Revisited.pptx
Python String Revisited.pptxPython String Revisited.pptx
Python String Revisited.pptx
 
C programming part4
C programming part4C programming part4
C programming part4
 
C programming part4
C programming part4C programming part4
C programming part4
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
 
String functions
String functionsString functions
String functions
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Python strings
Python stringsPython strings
Python strings
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdf
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 

More from Praveen M Jigajinni

Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithmsPraveen M Jigajinni
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructorsPraveen M Jigajinni
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programmingPraveen M Jigajinni
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with pythonPraveen M Jigajinni
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingPraveen M Jigajinni
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow chartsPraveen M Jigajinni
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingPraveen M Jigajinni
 

More from Praveen M Jigajinni (20)

Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithms
 
Chapter 08 data file handling
Chapter 08 data file handlingChapter 08 data file handling
Chapter 08 data file handling
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
Chapter 13 exceptional handling
Chapter 13 exceptional handlingChapter 13 exceptional handling
Chapter 13 exceptional handling
 
Chapter 10 data handling
Chapter 10 data handlingChapter 10 data handling
Chapter 10 data handling
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with python
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinking
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow charts
 
Chapter 5 boolean algebra
Chapter 5 boolean algebraChapter 5 boolean algebra
Chapter 5 boolean algebra
 
Chapter 4 number system
Chapter 4 number systemChapter 4 number system
Chapter 4 number system
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computing
 
Chapter 2 operating systems
Chapter 2 operating systemsChapter 2 operating systems
Chapter 2 operating systems
 
Chapter 1 computer fundamentals
Chapter 1 computer  fundamentalsChapter 1 computer  fundamentals
Chapter 1 computer fundamentals
 

Recently uploaded

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Chapter 14 strings

  • 2. Unit 2: Computational Thinking and Programming XI Computer Science (083) Board : CBSE Courtesy CBSE
  • 3. Unit II Computational Thinking and Programming (60 Theory periods 45 Practical Periods) DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci) Department of Computer Science, Sainik School Amaravathinagar Cell No: 9431453730 Praveen M Jigajinni Prepared by Courtesy CBSE
  • 5. Like many other popular programming languages, strings in Python are arrays of bytes representing Unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string. STRINGS
  • 6. How to change or delete a string?
  • 7. Strings are immutable. This means that elements of a string cannot be changed once it has been assigned. We can simply reassign different strings to the same name. >>> my_string = 'programiz' >>> my_string[5] = 'a' TypeError: 'str' object does not support item assignment. How to change or delete a string?
  • 8. How to create a string in Python?
  • 9. How to create a string in Python? Strings can be created by enclosing characters inside a single quote or double quotes. Even triple quotes can be used in Python but generally used to represent multiline strings and docstrings. STRINGS
  • 11. REPRESENTATION OF STRING >>> s = “Hello Python” This is how Python would index the string: Forward Indexing Backward Indexing
  • 13. STRINGS - Example Output Next Slide...
  • 15. How to access characters in a string?
  • 16. How to access characters in a string? We can access individual characters using indexing and a range of characters using slicing. Index starts from 0. Trying to access a character out of index range will raise an IndexError. The index must be an integer. We can't use float or other types, this will result into TypeError. STRINGS
  • 17. How to access characters in a string? Python allows negative indexing for its sequences. The index of -1 refers to the last item, -2 to the second last item and so on. We can access a range of items in a string by using the slicing operator (colon). STRINGS
  • 21. SLICING STRINGS EXAMPLES For example: >>>“Program”[3:5] will result in: ‘gr ’ >>>“Program”[3:6] will yield: ‘gra’ >>>p = “Program” >>>p [:4] ‘Prog’ >>>p = “Program” >>>p [4:] ‘ram’ >>>p = “Program” >>>p [3:6] ‘gra’
  • 25. More Functionality of String >>> len(“Sainik School”) 13 >>>print(“Sainik” + “School”) Sainik School >>>print(“A” * 4 ) AAAA >>>”sa” in “sainik” True >>>”pr” in “computer” False Finding Length of string String Concatenation String Repeat Substring Tests
  • 26. More Functionality of String >>> name1="computer" >>> name2=name1[3:5] >>>name2 pu String Slicing
  • 28. String Methods In Python, a method is a function that is defined with respect to a particular object. Syntax: object.method(arguments) For Example: >>>name=“Classic” >>>name.find(“s”) 3 the first position where “s” appears String object String Method Method Argument
  • 30. 1. capitalize() Method Capitalizes first letter of string First letter capitalization
  • 31. 2. lstrip() & 3. rstrip() Methods lstrip() method is used to remove left padded spaces in a given string >>>name1=“ a “ >>>name1.lstrip() ‘a ‘ rstrip() method is used to remove right padded spaces in a given string >>>name1.rstrip() ‘ a’ Removing left spaces Removing right spaces
  • 32. 4. strip() Method strip() method is used to remove left and right padded spaces in a given string >>>name1=“ a “ >>>name1.strip() ‘a‘ Removing left and right spaces for a given string
  • 33. 5. lower() Method lower() method is used to convert given string in to lower case. >>>name1=“ SAINIK “ >>>name1.lower() sainik Converting in to lower case
  • 34. 6. upper() Method upper() method is used to convert given string in to upper case. >>>name1=“ sainik “ >>>name1.upper() SAINIK Converting in to upper case
  • 35. 7. title() Method title() method is used to convert given string in to title case. Every first chatacter of word of a given string is converted to title case. >>>name1=“ praveen murigeppa jigajinni“ >>>name1.title() Praveen Murigeppa Jigajinni In every word first letter is capitalized
  • 36. 8. swapcase() Method swapcase() method is toggle the case. Meaining upper to lower and lower to upper case. >>>name1=“ PrAvEeN“ >>>name1.swapcase() pRaVeEn Every character case is changed
  • 37. 9. ljust() Method ljust() method is used to add spaces to the left side of the given string >>>name1=“ Jigajinni“ >>>name1.ljust(15) ‘Jigajinni ’ Left side padded with spaces Note: string length is 9 and 6 spaces added to the left side of string
  • 38. 10. rjust() Method rjust() method is used to add spaces to the right side of the given string >>>name1=“ Jigajinni“ >>>name1.rjust(15) ‘ Jigajinni’ Right side padded with spaces Note: string length is 9 and 6 spaces added to the right side of string
  • 39. 11. center(width, fillchar) Method The method center() returns centered in a string of length width. Padding is done using the specified fillchar. Default filler is a space. Centered string
  • 40. 12. zfill() Method zfill() method is used to fill the zero to a given string >>>name1=“ 123“ >>>name1.zfill(15) ‘00123 ’ Filling Zeros
  • 41. 13. find() Method find() method is used to find a perticular character or string in a given string. >>> name1="praveen" >>> name1.find("e") 4 e is present at 4th location (first appearance) in a given string
  • 42. 14. count() Method count() method is used to the number of times character or string appears in a given string. >>>name1=“praveen“ >>>name1.count(“e”) 2 2 times e appears in a given string
  • 43. 15. stratswith() Method startswith() method is used check string start with particular string or not >>>name1=“praveen“ >>>name1.startswith(“a”) False Given string not starting with “a”
  • 44. 16. endswith() Method endswith() method is used check string ends with particular string or not >>>name1=“praveen“ >>>name1.endswith(“en”) True Given string ends with “en”
  • 45. 17. isdigit() Method isdigit() method is used check string is digit (number) or not and returns Boolean value true or false. >>>name2=“123” >>>name2.isdigit() True >>name1=“123keyboard“ >>name1.isdigit() False Given string not number so false Given string is number
  • 46. 18. isnumeric() Method isnumeric() is similar to isdigit() method and is used check string is digit (number) or not and returns Boolean value true or false. >>>name2=“123” >>>name2.isnumeric() True >>name1=“123keyboard“ >>name1.isnumeric() False Given string not number so false Given string is number
  • 47. 19. isdecimal() Method isnumeric(),isdigit() and isdecimal() methods are used to check string is digit (number) or not and returns Boolean value true or false. >>>name2=“123” >>>name2.decimal() True >>name1=“123keyboard“ >>name1.isnumeric() False Given string not number so false Given string is number
  • 48. 20. isalpha() Method isalpha() method is used check string is digit or not and returns Boolean value true or false. >>>name2=“123” >>>name2.isalpha() False >>name1=“123computer“ >>name1.isalpha() False >>>name3=“Keynoard” >>>Name3.isaplpha() True Given string not string it contains digits Given string does not contain string It’s a string
  • 49. 21. isalnum() Method isalnum() method is used check string is alpha numeric string or not. >>>name2=“123” >>>name2.isalnum() True >>>name1=“123computer“ >>>name1.isalnum() True >>>name3=“Praveen” >>>name3.isalnum() True Given string is alpha numeric
  • 50. 22. islower() Method islower() method is used check string contains all lower case letters or not, it returns true or false result. >>>name2=“Praveen” >>>name2.islower() False >>>name1=“praveen“ >>>name1.islower() True Given string is not lower case string Given string is lower case string
  • 51. 23. isupper() Method isupper() method is used check string contains all letters upper case or not, it returns true or false result. >>>name2=“Praveen” >>>name2.isupper() False >>>name1=“PRAVEEN“ >>>name1.isupper() True Given string is not upper case string Given string is upper case string
  • 52. 24. isspace() Method isspace() method is used check string contains space only or not. >>>name2=“ ” >>>name2.isspace() True >>>name1=“PRAVEEN M J“ >>>name1.isspace() False Given string contains space only Given string not containing space only
  • 53. 25. find() Methods find() method is used to find a particular string (substring) in a given string. >>>name=“Classic” >>>name.find(“s”) 3 the first position where “s” appears String object String Method Method Argument
  • 54. 26. str() Method str() method is used convert non string data into string type. >>>str(576) ‘576’ 576 is number converted to string
  • 55. 27 len() Method len() method is used get a length of string. >>>len(“Praveen”) 7 Gives the string length
  • 56. 28 max() Method max() method is used get a max alphabet of string. >>>max(“Praveen”) v Gives max character
  • 57. 29 min() Method min() method is used get a max alphabet of string. >>>min(“Praveen”) P Gives min character P because it has ASCII Value 65
  • 58. 30 split() Method split() method is used split a string. Split in to several words or substrings
  • 59. 30 split() Method split() method is used split a string according to delimiter. Split in to several words or substrings according to delimiter
  • 60. 31 index() Method Same as find(), but raises an exception if str not found. >>> name="Sainik“ >>> name.index("a",3,5) ValueError: substring not found >>> name.index("a",1,5) 1 Value error Character found, returning the position
  • 62. 32. ord() Method ord() method is used get a ASCII value for a character. >>ord(“a”) 97 97 is the ASCII value for character ‘a’
  • 63. 33. chr() Method char() method is used get a character for an ASCII value. >>chr(97) ‘a’ ‘a’ ASCII value is 97
  • 65. Class Test Time: 40 Min Max Marks: 20 1. What is string? 02 2. What is forward indexing and back word indexing? 03 3. Explain any 5 string built in methods 10 4. What are character methods? Explain in detail 05