<jupyter_start><jupyter_text>Primitive Data Types--------------------These are the basic data types that constitute all of the more complex data structures in python. The basic data types are the following:* Strings (for text)* Numeric types (integers and decimals)* Booleans  String variablesString variables are used to store textual data, characters and sequences of characters. Can be specified by surrounding some text with single `'` or double `"` quotes.<jupyter_code>str_1 = "Hello World!"
print(str_1)
str_1 = "Hello World!"
print(str_1)<jupyter_output><empty_output><jupyter_text>Multiline stringsIf we have a piece of text with multiple lines, then triple quotes (either `'''` or `"""`) can be used to surround the text.<jupyter_code>str_2 = """
(CNN)AirAsia Flight QZ8501 climbed rapidly before it crashed,
a top Indonesian official said Tuesday, according to The Jakarta Post.

Then the plane stalled, Transportation Minister <NAME> said
at a parliamentary hearing, according to the AFP and Reuters news agencies.

"The plane, during the last minutes, went up faster than normal
speed ... after then, it stalled. That is according to the data
from the radar," Jonan said, according to the news agencies.
"""
print(str_2)
str_3 = """
If we want to have multiple lines in the string
then we can use triple quotes: This is a multiline
string!
"""
print(str_3)<jupyter_output><empty_output><jupyter_text>Operations on Strings We have seen some common operations on numeric variables. Now, let’s discuss a few **common** operations on string variables. The complete list of string operations is [available here](http://docs.python.org/3/library/string.html).  ConcatenationThe `+` operator concatenates two strings:<jupyter_code># note that + concatenates strings
str1 = "hello"
str2 = "world"
message = str1 + " " + str2 + "!"
print(message)<jupyter_output><empty_output><jupyter_text>Notice the difference of the `+` operation when operating on text vs. numeric variables:<jupyter_code>x = 41
x = x + 1
print(x)
x = "41"
x = x + "1"
print(x)<jupyter_output><empty_output><jupyter_text>ExerciseYou are given a variable `name = 'Panos'` and variable `phone = '212-998-0803'`. Use the values of these variables to create and print the message `Call Panos at 212-998-0803`.<jupyter_code>name = "Panos"
phone = "212-998-0803"
# your code here (2 lines)
message = "Call " + name + " at " + phone
print(message)<jupyter_output><empty_output><jupyter_text>String length`len(str)`: length of a string, number of characters<jupyter_code>word = "Python is the word. And on and on and on...."
print(len(word))
print(word)
print("The length of the text above is ", len(word), "characters")<jupyter_output><empty_output><jupyter_text>ExerciseYou are given a brief news article, stored in the variable `news`. Compute the length of the article, in characters.<jupyter_code>news = """
Technology stocks are suffering one of their worst beatings in years,
as investors reassess a sector that has been considered the growth
engine of the global economy but now faces the prospect of greater
regulatory scrutiny. The tech-heavy Nasdaq Composite Index
fell 2.9% Tuesday. That selloff carried over to the broader market,
where the S&P 500 index slumped 1.7%.  The Dow Jones Industrial
Average fell 1.4%, giving back some of Monday’s 2.8% rebound.
"""
print(len(news))
print(news)
print("The length of the text above is", len(news), "characters")<jupyter_output><empty_output><jupyter_text>CapitalizationNow let's see how we can change the capitalization of the text. This will also be our first, informal, introduction to a new type of function. * `str.upper()`: returns an uppercase version of a string* `str.lower()`: returns a lowercase version of a string<jupyter_code>print(news.lower())
print(news.upper())
# Notice that the original 'news' variable did not change
print(news)
# If we want to keep the changed-case version,
# we need to store it in a variable
l_news = news.lower()
print(l_news)<jupyter_output><empty_output><jupyter_text>Small deviationThe `.lower()` is a function that applies only to string variables. Notice the different way that we apply the function, compared to, say, the `len(news)` above. In this case, we have a string variable (`news`), then we have a dot (`.`), and then we put the name of the function: (`lower()`). Notice that we have the two parentheses at the end, which indicate that the function does not have any arguments, except for the `news` variable. Notice that if we omit the parentheses, we will get a strange result:<jupyter_code>news.lower<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09672522229451312, 'fraction_numerical': 0.014096725222294514, 'mean_word_length': 5.343878954607978, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '316270', 'license': 'CC0-1.0', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1316, 'n_words': 586, 'path': 'notes/D1-Strings_Basic_Operations.ipynb', 'repo_name': 'agill8781/python', 'size': '4619'}