# string creationtext = "Hello"text2 = 'World'multiline = """This isa multilinestring"""
# access characterstext = "Hello"text[0]#ans: 'H'text[-1]#ans: 'o'text[1]#ans: 'e'
# slice stringstext = "Hello, World!"text[0:5]#ans: 'Hello'text[7:]#ans: 'World!'text[:5]#ans: 'Hello'
# combine strings"Hello" + " " + "World"#ans: "Hello World"greeting = "Hello"name = "Alice"greeting + ", " + name#ans: "Hello, Alice"
# repeat strings"Ha" * 3#ans: "HaHaHa""=" * 10#ans: "=========="
# get lengthlen("Hello")#ans: 5len("")#ans: 0
# negative index?s = "Python"s[-1]#ans: 'n's[-2]#ans: 'o'
# slicing with step?s = "abcdefg"s[::2]#ans: 'aceg'
# reverse string?s = "Hello"s[::-1]#ans: 'olleH'
# string immutability?s = "Hello"s[0] = 'h'#ans: TypeError (strings are immutable)
# concatenation vs join?"a" + "b" + "c"#ans: "abc""".join(["a", "b", "c"])#ans: "abc"
# membership test?"ell" in "Hello"#ans: True"xyz" in "Hello"#ans: False
# empty string?s = ""len(s)#ans: 0bool(s)#ans: False
# string multiplication?"0" * 5#ans: "00000"
# escape characters?s = "Line1\nLine2"len(s)#ans: 11 (\n is one character)
# raw string?s = r"C:\new\path"#ans: "C:\\new\\path"
Google tag (gtag.js)