<jupyter_start><jupyter_text>Working with StringsNow that we've learned how to create strings, lets examine some of the more common things we can do with them.- Concatenation- Indexing & Slicing- String Immutability- Checking if a string is within another string  Concatenation<jupyter_code># You can concatenate (combine) multiple lines together using the + operator
leia = "I love you."
han = "I know."
print(leia + han)
# the previous example looks a bit weird, because when concatenating strings
# nothing else is added, so we have to manually add a space to it
print(leia + ' ' + han)<jupyter_output>I love you. I know.<jupyter_text>![](https://media.giphy.com/media/e6e1P3wC6xkYg/giphy.gif)  Indexing & Slicing- strings are sequences which means that they can be indexed and sliced- **string index:** the numerical location of a character within a string    - Indexing with all sequence types in Python starts at 0- **string silce:** a sub-string extracted from a string<jupyter_code># To view the value of a charater in a string, you must index
# into the string using open and close square brackets
# following the string or variable
ship = "<NAME>"
print(ship[0])
print("<NAME>"[0])
# slicing is done by using inserting a colon (:) in between the
# start and stop index to extract out the substring.  Notice the
# stop index isn't extracted.
print(ship[0:10])
ship[10]
# slicing doesn't need a start and stop.  Empty assume the first
# or last index depending on the situation
print(ship[:10])
ship[10:]<jupyter_output><empty_output><jupyter_text>Strings are Immutable- **immutability:** Unable to change the variable's associated value<jupyter_code>ship = '<NAME>'
ship + ' is the fastest in the galaxy'
ship
# You also can't change individual values of the string
ship[0] = 'S'<jupyter_output><empty_output><jupyter_text>![](https://media.giphy.com/media/3ornjSL2sBcPflIDiU/giphy.gif)<jupyter_code># you need to create a new variable (or overwrite the previous)
new_ship = "S" + ship[1:]
new_ship<jupyter_output><empty_output><jupyter_text>the `in` operator- the `in` operater checks to see if a value on the left is in the sequence on the right- returns `True` or `False`<jupyter_code>jedi_masters = "<NAME>, Yoda, <NAME>"
'Anakin' in jedi_masters<jupyter_output><empty_output><jupyter_text>![](https://3.bp.blogspot.com/-BJnqTMTBL6c/VrKYilX6R1I/AAAAAAAABs0/kSJ74wzE9ns/s1600/anakin%2Bcry.gif)<jupyter_code>council_members = "Anakin, <NAME>, Yoda, <NAME>"
'Anakin' in council_members<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10336633663366336, 'fraction_numerical': 0.013069306930693069, 'mean_word_length': 5.66490765171504, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '188206', 'license': 'MIT', 'n_tokens_mistral': 870, 'n_tokens_neox': 821, 'n_words': 292, 'path': 'Lecture Material/03_Strings_and_String_Methods/03.2-Working_With_Strings.ipynb', 'repo_name': 'knherrera/pcc-cis-012-intro-to-programming-python', 'size': '2584'}