<jupyter_start><jupyter_text>**** STRING METHODS ****<jupyter_code>import string

str1 = "String_methods_from_docpythonorg"
str2 = "uploading on github 1"
str3 = "02468"
str4 = "HelloWorld0123"
"""CAPATILIZE"""

print(str1.capitalize())
print(str2.capitalize())
"""Center"""

print(len(str2)) #19
print(str2.center(25,"*"))
"""Count"""

print("Occurence of o is " , str1.count("o"))
print("Occurence of o is " , str1.count("o",0,12)) #begining and ending index range

set_str1 = set(str1)
for i in set_str1:
    all = string.ascii_letters + string.digits + string.punctuation
    if i in all:
            print(i, "-->" , str1.count(i))

            
print("\nOR\n")
    
var = ""
for i in str1:
    if i not in var:
        var += i
        print(i , " --> " , str1.count(i), end = "  ~  ")
#str.decode
#str.encode
"""endswith"""

print(str2.endswith("h",0,17))
"""expandtabs"""

print("Practicing\tdoc.python".expandtabs(16)) #default is 8
"""find"""

print(str1.find("S")) #index number
print(str2.find("b",0,19)) #return -1 if not found
print(str2.find("b",0,18))
"""Format"""

print("String is {01} and {00}".format(str1,str2))

print("\nOR\n")

print(f"String is {str2} and {str1}")
"""index"""

print(str1.index("S"))
"""isalnum"""

print(str4.isalnum())
"""isalpha"""
c = "abcd"
print(str4.isalpha())
print(c.isalpha())
"""isidgit"""
b = "0123"
print(str4.isdigit())
print(b.isdigit())
"""islower"""

print(str2.islower())
"""isspace"""
a = "   "
print(str2.isspace())# when string is only space
print(a.isspace())
"""istitle"""
d = "Hello World"
print(str4.istitle())
print(d.istitle())
"""isupper"""

e = "HELLO WORLD"
print(str4.isupper())
print(e.isupper())
"""join"""

lst = ["a","b","c"]
print("-".join(lst)) 
"""ljust"""

print(str2.ljust(25,"*")) #one character long, not more than one
"""lower"""

r = "BYE"
print(r.lower())
"""lstrip"""

p = "     strip     ."
print(p.lstrip())
"""partition"""

string1 = "I am using partition method"
print(string1.partition('am'))
print(string1.partition('not')) #not is not present

string2 = "I am coding and I am using partition method"
print(string2.partition('am')) # splits at first occurence of 'am'
"""replace"""

print(string2.replace("am","was"))# replaces all am
print(string2.replace("am","was",1)) #only replaces one am 
print(string2.replace("am","was",2))
"""rfind"""

print(string1.rfind("am"))
print(string1.rfind("am",3)) #give -1 if not present 
print(string1.rfind("am",0,3))# at 3 index am lies so -1
print(string1.rfind("am",0,4))
"""rindex"""

print(string2.rindex("am")) #give result of the end am
print(string2.rindex("am",0,4))
print(string2.rindex("am",0,20))
"""rjust"""

print(len(string2))
print(string2.rjust(43+2,"*"))
"""rpartition"""

print(string2.rpartition("am"))#make 3 element tuple
print(string2.rpartition(" "))#######################################
"""rsplit"""

print(string1.rsplit(" "))
"""rstrip"""

print("   stripss   ".rstrip())#############################
"""split"""

print(string1.split())
print(string1.split(" "))
print("abc".split())
print("a .b .c".split(" ."))
print("1,,2".split(","))
print("1<>2<>3".split("<>"))
print('  1  2   3  '.split(None, 1))
"""splitlines"""

grocery = 'Milk\nChicken\r\nBread\rButter'

print(grocery.splitlines())
print(grocery.splitlines(True))
print(grocery.splitlines(0))
print(grocery.splitlines(1))

grocery = 'Milk Chicken Bread Butter'
print(grocery.splitlines())
"""Comparison between splitlines and split"""

print("".splitlines())
print("One line\n".splitlines())

print(''.split('\n'))
print('Two lines\n'.split('\n'))

#print(''.splitlines('\n'))                      #error (only integer can pass)
#print('Two lines\n'.splitlines('\n'))           #error (only integer can pass)<jupyter_output>[]
['One line']
['']
['Two lines', '']<jupyter_text>Representation               --->                    Description\n                           --->                    Line Feed\r                           --->                    Carriage Return\r\n                         --->                    Carriage Return + Line Feed\v or \x0b                   --->                    Line Tabulation\f or \x0c                   --->                    Form Feed\x1c                         --->                    File Separator\x1d                         --->                    Group Separator\x1e                         --->                    Record Separator\x85                         --->                    Next Line (C1 Control Code)\u2028                       --->                    Line Separator\u2029                       --->                    Paragraph Separator<jupyter_code>"""startswith"""

print(str2.startswith("u",0,17))
print(str2.startswith("l",2,20))
"""strip"""

st = "     strip    "
print(st.strip()) # remove both left right spaces
"""swapcase"""

print("HeLLo".swapcase())  #swap uppercase into lowercase
print("bye".swapcase())
"""title"""

print(str2.title())
"""translate"""

# using ASCII   
trans = {103: None, 101: None, 101: None} 
  
string4 = "hello"
print(string4.translate(trans)) #can remove nd replace number

print("\nOR\n")

firstString = "abc"
secondString = "ghi"
thirdString = "ab"
string5 = "abcdef"
translation = string5.maketrans(firstString, secondString, thirdString)
print(translation)
print(string5.translate(translation))##############################
"""upper"""

print(str2.upper())
"""zfill"""

#zfill() method returns a copy of the string with ‘0’ characters padded to the leftside of the given string.
print(str2.zfill(19+10))
print(str2.zfill(18))  # Given length is less than the length of original string
print("-280".zfill(10)) #If a string starts with the sign prefix('+', '-'), the '0' digits are filled after the first sign.
print("!@@#$%^&_+_-".zfill(20))
print("-!@@#$%^&_+_-".zfill(20))
"""isdecimal , isdigit , isnumeric"""

c = '\u2155'
print(c)
print(c.isdecimal(), c.isdigit(), c.isnumeric())
c = '\u00B2'
print(c)
print(c.isdecimal(), c.isdigit(), c.isnumeric())

print("\nOR\n")

# f = "10.02"
f = "10"
print(f.isdecimal())
print(f.isnumeric())
print(f.isdigit())<jupyter_output>⅕
False False True
²
False True True

OR

True
True
True
{'fraction_non_alphanumeric': 0.21607142857142858, 'fraction_numerical': 0.03198051948051948, 'mean_word_length': 3.347918136908963, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '242408', 'license': 'MIT', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2141, 'n_words': 474, 'path': 'Python/String Methods Python.ipynb', 'repo_name': 'udit6023/Hacktoberfest2021', 'size': '6160'}