<jupyter_start><jupyter_text>Lesson 2 - Introduction to Strings  In Python, there are many ways to represent text with strings, in order to handle things like apostrophes, quotation marks, and multiple lines. You can assign a string value to a **variable** using double quotes.  Execute the cell below (press Shift-Enter in the cell) to assign a string value to the variable `message`. Then use the next cell to print the value of `message`.  Double Quotes<jupyter_code>message = "Meet me tonight."
print(message)<jupyter_output><empty_output><jupyter_text>Note that the print command above doesn't use quotes. What do you think the cell below will print?  Run it to see what happens.  There will be more about this later, but the print function accepts variables and literals.<jupyter_code>print("message")<jupyter_output><empty_output><jupyter_text>Single Quotes You can also put a string inside single quotes.<jupyter_code>message2 = 'Type your own message here.'<jupyter_output><empty_output><jupyter_text>After you run the cell above to assign your message to `message2`, enter a Python command below to print the value of `message2` and then execute it.  Quoting Quotes Why does Python allow both double and single quotes?  Execute the following cell to see what can go wrong with using single quotes.<jupyter_code>message3 = 'I'm looking for someone to share in an adventure.'<jupyter_output><empty_output><jupyter_text>The Python interpreter thinks the apostrophe in *I'm* is the end quote, and it can't understand the rest of the line, so it gives a syntax error starting right after the second quote.   Escape character \One way you can fix the error by adding a backslash \ before the apostrophe you want to print. The backslash is called an "escape character" and tells Python to accept the next character as part of the string. Add a backslash before the apostrophe in *I'm* to fix the code below, then check it with the print statement.<jupyter_code>message3 = 'I\'m looking for someone to share in an adventure.'
print(message3)<jupyter_output><empty_output><jupyter_text>Quotes in QuotesBut, thanks to the fact that Python also allows double quotes, the more elegant way to include apostrophes in your string is to enclose the whole string in double quotes.  Try using double quotes to fix the line below.  Jupyter Note: Jupyter will automatically close your quotes for you as you type, so you will need to delete any extra quotes that you don't want.  Autoclose is a Jupyter feature that can be turned off, but we'll just have to deal with it now!<jupyter_code>message3 = 'I'm looking for someone to share in an adventure.'
print(message3)<jupyter_output><empty_output><jupyter_text>Triple QuotesMore complex quoting requirements can be handled with triple quotes.  You can quote single and double quotes as well as line feeds with triple quotes.  Here's an example...<jupyter_code>movie_quote = """One of my favorite lines from The Godfather is:
"I'm gong to make him an offer he can't refuse."
Do you know who said this?"""
print(movie_quote)
print("socratica".upper())  # Just playing around - strings have methods<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.059102402022756004, 'fraction_numerical': 0.0028445006321112516, 'mean_word_length': 5.25494071146245, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '201008', 'license': 'MIT', 'n_tokens_mistral': 867, 'n_tokens_neox': 836, 'n_words': 446, 'path': '02 Introduction to Strings.ipynb', 'repo_name': 'real-numbers/pythonLessons', 'size': '3164'}