- Day : Sunday
- Date : 2025-09-07
- Time : 16:05
- Tags : #python #revised #strings
- References : [[RevisedNotes]] , [[FunctionsStrings]] , [[ImportantQuestionsSrtings1]]
- Branch of : Python > RevisedNotes > RevisedNotesStrings
- Author : dx
-
len() : length, iterable must, else
TypeError -
l.upper(),l.lower(): return newstr, none Error -
l.capatlize(): first letter of first word , None -
l.title(): First letter of each word ,None -
l.strip(),l.rstrip(),l.lstrip(): it will by default remove space\n\t\r\f\vpadding, or specified padding even!@can remove!!!!!!!!!!@@@@@@@, None Error -
l.replace(oldsubstr,newstr,count): it will give a new str by repalacing that ,TypeErrorif not string, or not at least 2 arg, no error if sub str not found -
l.find(substr, start, end)orl.rfind(): it will give the index of 1sst occuracnce , from left or , right , Give-1if not found , NO error -
l.index(substr, start, end),l.rfind(): it will give the first occurance of str , from left/right ,ValueErrorif not found -
l.count(str, start, end): it will count the occurance of str , no error , even not index out of range error -
l.split("SEPERAROR", MAXsplits)/l.rsplit(): it will split the str into parts acc to substring passed, it doesn’t give separator in splitted list , None , GIVES LIST , Gives full str if separator not present -
l.partition("SEPERATOOR"): it will give a TUPLE of first split of str with the seperator ,ValueErrorif not present -
"SEPERATOR".join(iterable): Join the iterable with the seperator,TypeErrorif not iterable or notstr -
l.startswith(substr, start, end)/l.endswith(): Return true if condition True, Output Typebool, no Error -
str.isalpha()/str.isdigit()/str.isalnum()/str.isspace()/str.islower()/str.isupper()/str.istitle(): ReturnTrueorFalseif the condition satisfy, NO arg required -
l.zfill(TOTALLENGTH): it will pad the str left with zeroes and preserve sign , Pad as total length -
str.encode()-
Syntax:
string.encode(encoding='utf-8') -
Input:
str -
Output:
bytes -
Error:
UnicodeEncodeErrorif characters can’t be encoded. -
Example:
"hello".encode()→b'hello'
"hello".encode() # b'hello' (5 bytes: 68 65 6c 6c 6f in hex) "♥".encode("utf-8") # b'\xe2\x99\xa5' (3 bytes in UTF-8)
bis byte literal -
-
str.format()/str.format_map()-
Syntax:
string.format(*args, **kwargs)/string.format_map(mapping) -
Input:
strwith placeholders -
Output:
str -
Error:
KeyError/IndexErrorif placeholders missing. -
Example:
"Hello {}".format("World")→"Hello World"
-
-
str.casefold()-
Syntax:
string.casefold() -
Input:
str -
Output:
str -
Error: None
-
Example:
"Straße".casefold()→"strasse" -
Use: For aggressive lowercasing → best for case-insensitive comparison, especially with non-English text.
-