Let's practice with strings:
string_1 = 'Single quoted string' string_2 = "Sometimes it's good to use double quotes" multiline_string = """ This string contains single quotes ' and double quotes " and spans multiple lines""" print(string_1) print(string_2) print(multiline_string) numerical_value = 1.616233 print('The value is ' + str(numerical_value))
The result should look like this:
A string literal is an arbitrary sequence of characters enclosed in quotation marks, such as 'Single quoted string'
in the example above. String literals can be assigned to variables, like any other type. Single or double quotes can be used. If you need to use a single quote within the string, you need to enclose the string in double quotes, as we did with the string literal assigned to the variable string_2
. Enclosing a string in triple quotes (either single or double) allows you to include newlines and quotation marks in the string. We used triple...