0% found this document useful (0 votes)
10 views2 pages

String Manipulation

The document describes various string manipulation functions in Python. It lists 25 functions including ord(), chr(), len(), capitalize(), find(), count(), isalnum(), isalpha(), isdigit(), islower(), isupper(), isspace(), lower(), upper(), replace(), lstrip(), rstrip(), strip(), startswith(), endswith(), title(), istitle(), join(), swapcase(), split(), and partition() and provides examples of their use.

Uploaded by

adarsh.rajesh69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

String Manipulation

The document describes various string manipulation functions in Python. It lists 25 functions including ord(), chr(), len(), capitalize(), find(), count(), isalnum(), isalpha(), isdigit(), islower(), isupper(), isspace(), lower(), upper(), replace(), lstrip(), rstrip(), strip(), startswith(), endswith(), title(), istitle(), join(), swapcase(), split(), and partition() and provides examples of their use.

Uploaded by

adarsh.rajesh69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

STRING MANIPULATION

Function name USE/Syntax


1. ord() Returns the ASCII value of the character
>>ord(‘A’)
>>65
2. chr() Returns the character for the particular ASCII value
>>chr(48)
>>'0'
3. len() Returns the total number of characters in the string
4. capitalize() Returns a copy with its first character capitalized.
>> 'hi to All'.capitalize()
>>'Hi to all'
find(sub, start, end ) Returns the index of first occurrence of the substring (if found). If not
found, it returns -1.
>>st='Hello All'
>>st.find('l')
>>2
>>st.find('L')
>>-1

5. count() Returns the number of occurrences of a substring in the given string.


>>st='Hello All'
>>st.count(‘l’)
>>4

6. isalnum() Returns True if the character in the string are alphanumeric(Alphabets


or numbers) and there is atleast one character, otherwise it returns
False.
7. isalpha() Returns True if all the characters in the string are alphabetic and there
is atleast one character, otherwise False.
8. isdigit() Returns True if all the characters in the string are digits and there is
atleast one character, otherwise False.
9. islower() Returns True if all the cased characters in the string are in lower case
and there is atleast one cased character, otherwise False.
10. isupper() Returns True if all the cased characters in the string are in upper case
and there is atleast one cased character, otherwise False.
11. isspace() Returns True if there are only whitespaces characters in the string.
There must be at least one character. Otherwise it returns False.
12. lower() Returns a copy of the string converted to lowercase.
13. upper() Returns a copy of the string converted to uppercase
14. replace(old,new,count) Replaces a specified phrase with another specified phrase.
15. lstrip() Returns a copy of the string with leading whitespaces removed from
the left.
>>st='Hello All'
>>st.lstrip('leH')
>>'o All'
16. rstrip() Returns a copy of the string with leading whitespaces removed from
the right.
17. strip() Returns a copy of the string with leading and trailing white spaces
removed.
<string>.strip()

18. startswith() Returns True if the string starts with the substring otherwise False.
>>st='Hello All'
>>st.startswith('H')
>>True
19. endswith() Returns True if the string ends with the substring otherwise False.
>>'abcdef'.endswith('ab')
>>False
20. title() It returns a title-cased version of the string where all words starts with
uppercase characters and all remaining letters are in lowercase.
>>'all is 78well'.title()
>>'All Is 78Well'
21. istitle() Returns True if the string has the title case, i.e the first letter of each
word in upper case, while the rest of the letter in lowercase, False
otherwise.
22. join() joins a string or character after each member of the string iterator, i.e a
string based sequence
<string>.join(<string iterable>)

23. swapcase() Returns a copy of the string <str> with upper case characters
converted to lowercase and vice versa.
>>'Hello All'.swapcase()
>>'hELLO aLL'
24. split() The split() method splits a string into a list.
>>st='All is well'
>>st.split()
>>['All', 'is', 'well']
>>st.split('is')
>>['All ', ' well']
25. partition() The partition method splits the string at the first occurrence of
separator ad returns a tuple containing three items:
a. The part before the separator
b. The separator itself
c. The part after the separator
>>st='All is well'
>>st.partition('is')
>>('All ', 'is', ' well')

You might also like