Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Perfect Notes Computer ch- Sting in Python

Rating
-
Sold
-
Pages
8
Uploaded on
08-12-2024
Written in
2024/2025

This comprehensive PDF is designed for Class 11 & 12 students to master the concept of Strings in Python. It includes: Clear explanations of string manipulation, slicing, and built-in methods. Examples and practice problems tailored for CBSE and other board curricula. Step-by-step coding solutions to reinforce understanding. Ideal for beginners and those preparing for school exams or practicals.

Show more Read less
Institution
Course

Content preview

Chapter 4: String in Python
==============================================
String :-------->
String is a sequence which is made up of one or more UNICODE characters.
Here the character can be a letter, digit, whitespace or any other symbols.
* A string can be created by enclosing one or more characters in single, double or triple
quote.
* Every character has a unique position / index.
* There are two types on indexes. These are:
• Forward Index
• Backward Index
• Forward index starts from front as 0 for 1st element and ends with length / size – 1 for
the last element.
• Backward index starts from back as -1 for last element and ends with length / size * -1
for the first element.

Accessing Characters in a String =======>
• Each individual character in a string can be accessed using a technique called
indexing.
• The index specifies the character to be accessed in the string and is written in square
brackets ([ ]).
e.g. suppose s is string......
0 1 2 3 4 5 6
S T E P H E N
-7 -6 -5 -4 -3 -2 -1
If we want to access....
Second character s [ 1 ] or s [ -6 ]
Last character s [ 6 ] or s [ -1 ]

String is Immutable ====>
• A string is an immutable data type.
• It means that the contents of the string cannot be changed after it has been created.
St = "Hello"
St[0] = 'M'
print(St) --------> Error

Features of String : ⇒⇒
* It is immutable in nature.
* It follows insertion order.
* It follows the indexing and slicing concept.
* It can store any UNICODE character within single/double/triple quote.

String Operations ===>
Python allows certain operations on string data type, such as concatenation,repetition,


1

, membership and slicing.

* Concatenation ( + )
Concatenate means to join. Python allows us to join two strings using concatenation
operator plus which is denoted by symbol +.
Concatenation can take place only when both the operands / values are of string type.
If any value is of another type then it will result in Error.
e.g.
"cat" + "mat" -----> catmat
'5' + '3' ------> 53
'5' + 3 ------> Error

* Replication ( * )
Python allows us to repeat the given String. It can be done using repetition operator
which is denoted by symbol *
Note:-->
Replication can take place only when one of the operands/ values are of string type and the
other operand is of int
i.e. Number type value.
e.g.
'cat' * 3 --------> catcatcat
'5' * 4 ----------> 5555
3 * "7" ----------> 777
'5' * '2' ----------> Error

* Membership ( in / not in )
There are two membership operators in Python. They are in and not in. • These are used to
search for the presence of a character / sub string in another string.
They return their result in the form of True / False.
e.g.
'N' in "MANGO" ------> True
"ics" in "Phyics" -------> True
'd' in "hello' --------> False
'come' not in "welcome" ----> False

* Comparison
String are compared on the basis of lexicographical ordering.
The comparison is done on the basis of ASCII / Ordinal values. These are:
Character Ordinal Values
0–9 48 to 57
A–Z 65 to 90
a–z 97 to 122
Space 32
e.g.
if "Ram" > "Raj" ---------> True




2

Written for

Institution
Secondary school
Course
School year
1

Document information

Uploaded on
December 8, 2024
Number of pages
8
Written in
2024/2025
Type
Class notes
Professor(s)
Sir. vaibhav sharma
Contains
11th

Subjects

$7.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
vaibhavfactin

Get to know the seller

Seller avatar
vaibhavfactin
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions