# upper and lower"hello".upper()#ans: "HELLO""HELLO".lower()#ans: "hello""hello world".title()#ans: "Hello World""hello".capitalize()#ans: "Hello"
# remove whitespace" hello ".strip()#ans: "hello"" hello ".lstrip()#ans: "hello "" hello ".rstrip()#ans: " hello"
# split string"apple,banana,cherry".split(",")#ans: ['apple', 'banana', 'cherry']"one two three".split()#ans: ['one', 'two', 'three']
# join list to string",".join(["a", "b", "c"])#ans: "a,b,c"" ".join(["Hello", "World"])#ans: "Hello World"
# find substring"hello world".find("world")#ans: 6"hello world".find("xyz")#ans: -1"hello world".index("world")#ans: 6
# replace substring"hello world".replace("world", "Python")#ans: "hello Python""aaa".replace("a", "b", 2)#ans: "bba" (replace first 2)
# check start and end"hello".startswith("he")#ans: True"hello".endswith("lo")#ans: True
# count occurrences"hello".count("l")#ans: 2"banana".count("a")#ans: 3
# case methods?"HeLLo".lower()#ans: "hello""hello".upper()#ans: "HELLO"
# strip only ends?" hello ".strip()#ans: "hello"
# split with limit?"a-b-c-d".split("-", 2)#ans: ['a', 'b', 'c-d']
# join with numbers?"-".join([1, 2, 3])#ans: TypeError (needs strings)"-".join(["1", "2", "3"])#ans: "1-2-3"
# find vs index?"hello".find("x")#ans: -1"hello".index("x")#ans: ValueError
# replace all?"aaa".replace("a", "b")#ans: "bbb"
# case sensitive?"Hello".startswith("h")#ans: False"Hello".startswith("H")#ans: True
# count overlapping?"aaa".count("aa")#ans: 1 (non-overlapping)
# empty split?"".split()#ans: []" ".split()#ans: []
# join empty list?",".join([])#ans: ""
Google tag (gtag.js)