String Operations - Advanced
Posted: Sun May 26, 2024 10:08 am
Splitting the split based on location
#Splitting the split based on location
Code: Select all
b = "Hello, ICAI!"
print(b[2:5])#Modifying a String
Code: Select all
#Modifying a String
a = "Hello, ICAI!"
print(a.upper())Code: Select all
#Concatenate string (INT07)
a = "Hello"
b = "ICAI"
c = a + b
print(c)Code: Select all
#Escape Char
#\
print("This is a double quote: \"")
print("This is a single quote: \'")
print("This is a backslash: \\")
#t
print("This is on one line.\nThis is on the next line.")
print("This\tis\ta\ttabbed\tline.")#Capitalize First Character
Code: Select all
text = " python for ca students "
print("Capitalize:", text.strip().capitalize())Code: Select all
text2 = "banana"
print("Count of 'a':", text2.count('a'))Code: Select all
text3 = "hello"
print("Index of 'e':", text3.index('e'))Code: Select all
print("Is Alphanumeric ('abc123'):", "abc123".isalnum())Code: Select all
print("Is Alphabetic ('python'):", "python".isalpha())Code: Select all
print("Is Decimal ('2025'):", "2025".isdecimal())Code: Select all
print("Is Digit ('123'):", "123".isdigit())Code: Select all
print("Is Lowercase ('lowercase'):", "lowercase".islower())Code: Select all
print("Is Numeric ('123456'):", "123456".isnumeric())Code: Select all
words = ["CA", "Final"]
print("Join with space:", " ".join(words))Code: Select all
print("Lowercase ('TAX'):", "TAX".lower())Code: Select all
print("Replace 'audit' with 'final':", "audit report".replace("audit", "final"))Code: Select all
print("Starts with 'In':", "Income Tax".startswith("In"))Code: Select all
text = " python for ca students "
print("Stripped:", text.strip())Code: Select all
print("Swapcase ('PyTHon'):", "PyTHon".swapcase())Code: Select all
print("Title Case ('advanced tax laws'):", "advanced tax laws".title())Code: Select all
print("Uppercase ('python'):", "python".upper())