What is a string in Python? code example
Example 1: pyhon string
my_string = 'Hello'
print(my_string)
my_string = "Hello"
print(my_string)
my_string = '''Hello'''
print(my_string)
my_string = """Hello, welcome to
the world of Python"""
print(my_string)
Example 2: 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 3: strings in python
myString = "Hello world"
print(myString)
myArr = []
myArr.append(myString)
H = myString[0]
lowercase = myString.lower()
myInt = int(myString)
Example 4: define a string in python
string1 = "something"
string2 = 'something else'
string3 = """
something
super
long
"""