Strings in python are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
Assigning a string to a variable is done with the variable name followed by an equal sign and the string:
a = "Hello" print(a)
You can assign a multiline string to a variable by using three quotes (either """ or '''):
a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.""" print(a)
You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string. (Note: The first character has index 0).
b = "Hello, World!" print(b[2:5]) // Output: llo
Python has a set of built-in methods that you can use on strings.
upper(): Returns the string in upper case.lower(): Returns the string in lower case.strip(): Removes whitespace from the beginning or the end.replace(): Replaces a string with another string.split(): Splits the string into substrings if it finds instances of the separator.
a = " Hello, World! "
print(a.strip()) // "Hello, World!"
print(a.upper()) // " HELLO, WORLD! "
print(a.replace("H", "J")) // " Jello, World! "
Which method is used to remove whitespace from the beginning and end of a string?