STRING
String is a sequence of characters or elements present inside single quotes
‘ ’, double quotes “ ” ,and triple quotes ‘“ ”’ . that entire data is known as string.
String represents textual data like
1 ) Alphabets — a-z, A-Z
2 ) Numbers — 0–9
3 ) special symbols — @,#,%,$,& etc.
*PROPERTIES OF STRING
- Sequential Data (Mutable Data)
string is a sequential data type . once we create data, we can perform 3 actions.
— Adding a new element
— Replacing an existing element
— Deleting / removing an existing element
2 . Immutable Data
Once we create a string , we cannot change a character after creating it. if we try to change it, it gives an error.
In immutable data, we cannot perform these 3 actions :
— Adding a new element
— Replacing an existing element
— Deleting / removing an existing element
3 . Indexed Data
Each and evert character has its own index value .string has both positive and negative index values
— Positive index starts from 0 to + infinity
— Negative index starts from -1 to- infinity
To access a single element / character in a string, we have 2 methods
- INDEXING
- SLICING
Indexing :- Every character has a position number (index). index starts from 0.
THERE ARE 2 INDEXING
. Positive indexing :- left to right( 0,1,2,3,…….)
. Negative indexing :- right to left(-1,-2,-3,-……..)
EXAMPLE :
Slicing :- Slicing is a method to access a group of sequential characters in a string using index.
Syntax. s[start : stop]
EXAMPLE:-
STRING METHODS
String method are a bunch of methods or functions which we can apply only on string data type. we cannot apply these methods on any other data type, if we apply we will get an attribute error.
syntax :- string. method()
*CASE CHANGING METHODs
1)uppercase()
It is a string method .It is used to converts all the lower characters in a string into uppercase letters.
EXAMPLE 1
EXAMPLE 2
2) lowercase()
It is a string method. it is use to converts all the upper characters in a string into lower letters.
EXAMPLE 1
3. swapcase()
It is a string method, it is used to converts uppercase letters into lowercase letters , and lowercase letters into upper case letters .
EXAMPLE
4. capitalize()
It converts only the first letter of the string into uppercase and remaining letters into lowercase.
EXAMPLE 1
EXAMPLE 2
5. title()
It is used to converts the first letter of each word into uppercase and remaining letters into lowercase.
EXAMPLE 1
6) count( )
It is a string method, used to count, how many times a specific character occurred in a string.
EXAMPLE
7) index()
Get Sivala Sowjanya’s stories in your inbox
Join Medium for free to get updates from this writer.
used to give index value of a sub String, it will consider while occurring at first occurrence when python is scanning from left to right.
EXAMPLE
8) Find()
Both index and find returns index of first occurence of subString and the only difference is, if we are searching for index of substring that is not available, it will return o/p as “-1”.
EXAMPLE
9) Strip()
It is a string method, used to remove the first character in the substring from the beginning of the string to end of the string.
EXAMPLE
10) lStrip()
It is a string method, used to remove the first character in the substring only from the beginning of the string.
EXAMPLE
11) rStrip()
It is a string method, used to remove the first character in the substring only from the Ending of the string.
EXAMPLE
12) split()
It is a string method, used to split the String into sub string based on the given sub string.
EXAMPLE
13) rsplit()
It is a string method that splits a string from right to left while forming the resulting groups from left to right.
EXAMPLE
14) replace()
It is a string method used to replace an existing character or sequence of characters with another character or group of characters.
EXAMPLE
15) rfind()
It is a string method used to find and return the index position of a character in a string, starting the search from the right side (end of the string)
EXAMPLE
16) rindex()
It is a string method used to find and return the index position of a character by searching from the right side of the string.
EXAMPLE
17) isupper()
It return true, if all characters are in uppercase.
which is used to check if all the alphabets are in uppercase.
EXAMPLE
18) islower()
It return true, if all characters are in lowercase.
which is used to check if all alphabets are in lowercase.
EXAMPLE1
EXAMPLE 2
19) istitle()
It return true ,if the string is in the titlecase.
EXAMPLE
20) isdigit()
It return true, if all the characters are digits(0 to 9) otherwise it will be false.
EXAMPLE
21) isalpha()
It return true, if all characters are alphabets, otherwise it will be false.
EXAMPLE
22) is alnum()
It returns true ,if all characters are alphabets or digits ,otherwise it will be false.
EXAMPLE





