Open cornydude247 opened 3 years ago
str = 'programiz' print('str = ', str)
print('str[0] = ', str[0])
print('str[-1] = ', str[-1])
print('str[1:5] = ', str[1:5])
print('str[5:-2] = ', str[5:-2])
my_string = 'programiz' my_string[5] = 'a' ... TypeError: 'str' object does not support item assignment my_string = 'Python' my_string 'Python'
del my_string[1] ... TypeError: 'str' object doesn't support item deletion del my_string my_string ... NameError: name 'my_string' is not defined
print('str1 + str2 = ', str1 + str2)
defining strings in Python
all of the following are equivalent
my_string = 'Hello' print(my_string)
my_string = "Hello" print(my_string)
my_string = '''Hello''' print(my_string)
triple quotes string can extend multiple lines
my_string = """Hello, welcome to the world of Python""" print(my_string)