python string manipulation code example
Example 1: python string cut
string = "freeCodeCamp"
print(string[0:len(string)-1])
print(string[0:5])
print(string[2:6])
print(string[-1])
print(string[-5:])
print(string[1:-4])
print(string[-5:-2])
print(string[::2])
Example 2: python edit string variable
text = 'abcdefg'
new = list(text)
new[6] = 'W'
''.join(new)
Example 3: string in python
string = "String"
string = str(string)
s1 = "Str"
s2 = "ing"
s = s1 + s2
Example 4: strings in python
myString = "Hello world"
print(myString)
myArr = []
myArr.append(myString)
H = myString[0]
lowercase = myString.lower()
myInt = int(myString)
Example 5: {} string python
txt1 = "My name is {fname}, I'm {age}".format(fname = "John", age = 36)
txt2 = "My name is {0}, I'm {1}".format("John",36)
txt3 = "My name is {}, I'm {}".format("John",36)
Example 6: python string
print("Hello")
print('Hello')