Page 1 of 1

String Operations - Advanced

Posted: Sun May 26, 2024 10:08 am
by admin

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())
Concatenate string (INT07)

Code: Select all

#Concatenate string (INT07)
a = "Hello"
b = "ICAI"
c = a + b
print(c)
#Escape Char

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())
#Count Occurrences

Code: Select all

text2 = "banana"
print("Count of 'a':", text2.count('a'))
#Find Index

Code: Select all

text3 = "hello"
print("Index of 'e':", text3.index('e'))
#Check Alphanumeric

Code: Select all

print("Is Alphanumeric ('abc123'):", "abc123".isalnum())
#Check Alphabetic

Code: Select all

print("Is Alphabetic ('python'):", "python".isalpha())
#Check Decimal

Code: Select all

print("Is Decimal ('2025'):", "2025".isdecimal())
#Check Digits

Code: Select all

print("Is Digit ('123'):", "123".isdigit())
#Check Lowercase

Code: Select all

print("Is Lowercase ('lowercase'):", "lowercase".islower())
#Check Numeric

Code: Select all

print("Is Numeric ('123456'):", "123456".isnumeric())
#Join Words with Space

Code: Select all

words = ["CA", "Final"]
print("Join with space:", " ".join(words))
#Convert to Lowercase

Code: Select all

print("Lowercase ('TAX'):", "TAX".lower())
#Replace Substring

Code: Select all

print("Replace 'audit' with 'final':", "audit report".replace("audit", "final"))
#Startswith Check

Code: Select all

print("Starts with 'In':", "Income Tax".startswith("In"))
#Remove Whitespace

Code: Select all

text = "  python for ca students  "
print("Stripped:", text.strip())
#Swap Case

Code: Select all

print("Swapcase ('PyTHon'):", "PyTHon".swapcase())
#Title Case

Code: Select all

print("Title Case ('advanced tax laws'):", "advanced tax laws".title())
#Convert to Uppercase

Code: Select all

print("Uppercase ('python'):", "python".upper())

Re: String Operations - Advanced

Posted: Mon May 27, 2024 8:09 am
by admin
Sir i got a errot like this