<jupyter_start><jupyter_text>Please go to https://ccv.jupyter.brown.edu    What we learned so far... - What are Jupyter notebooks- What are variables- How to work with number and boolean variables   String Variables  By the end of the day you'll be able to - Describe and create characters and strings- Index strings- Use string operations- Describe special characters- Convert strings to numbers and numbers to strings   Variables Review * You assign a value to a variable using the `=` sign.* You can change the value assigned to a variable.* Data is represented as numbers, strings, or boolean variables.* Numbers can be integers (whole numbers) or floats (numbers with decimal points).* Boolean variables can have only two values: True or False. - Describe and create characters and strings- Index strings - Use string operations - Describe special characters - Convert strings to numbers and numbers to strings    Characters<jupyter_code>a_lowercase_str = 'a'
print(a_lowercase_str)
another_lowercase_str = "b"
print(another_lowercase_str) 
an_uppercase_str = 'Z'
print(an_uppercase_str)<jupyter_output><empty_output><jupyter_text>Exercise: Define a character variable called `another_uppercase_str` and assign the value "A" to it. Then, print the variable.<jupyter_code>from gofer.ok import check
# write your code below this line


# write your code above this line

check('tests/lec2_p1.py')
a_number_str = '9'
print(a_number_str)

# a_number_char + 6
a_symbol_str = '-' 
print(a_symbol_str)
combined_str = a_lowercase_str + a_number_str
print(combined_str)<jupyter_output><empty_output><jupyter_text>Exercise: Create a variable called `comb_str` and using the character variables we defined, assign the value "A-Z" to it. Then, print it.<jupyter_code># write your code above this line
check('tests/lec2_p2.py')<jupyter_output><empty_output><jupyter_text>Strings<jupyter_code>short_str = "string"
longer_str = 'This is my first string!'

print(short_str)
print(longer_str) 
# beware of apostrophe in strings!

# NOT VALID
print('There's my first string!')

# VALID
print("There's my first string!")<jupyter_output><empty_output><jupyter_text>Exercise: define a variable called `exercise_str` and assign the following sentence to it: `This is a sentence that I have assigned to the variable, "exercise string".` Then, print it.<jupyter_code># write your code above this line
check('tests/lec2_p3.py')<jupyter_output><empty_output><jupyter_text>-  Describe and create characters and strings - Index strings- Use string operations - Describe special characters - Convert strings to numbers and numbers to strings    String indexing   string[*starting index* : *stopping index* : *step size*]  Default Values:* start = beginning of string* stop = end of string* step = 1<jupyter_code>my_name_str = '<NAME>'

# indexing one character
print(my_name_str[0])
print(my_name_str[1])
print(my_name_str[-3])
# indexing a range of characters
print(my_name_str[0:3]) # stop index is not included
print(my_name_str[3:])
print(my_name_str[:6]) 
# indexing a range of characters with a step
print(my_name_str[::2])
print(my_name_str[1::3]) 
print(my_name_str[::]) # default step size = 1
# backwards indexing
print(my_name_str[::-1])<jupyter_output><empty_output><jupyter_text>Exercise: Indexing a string`my_name_str = '<NAME>'`* Assign the initial of the last name to `a_str`* Assign the last four characters to `b_str`* Assign every second character to `c_str`* Assign every third character in reverse order to `d_str`* Assign the characters between the second and the sixth location to `e_str`* Print all variables<jupyter_code>my_name_str = '<NAME>'


# write your code above this line
check('tests/lec2_p4.py')<jupyter_output><empty_output><jupyter_text>-  Describe and create characters and strings - Index strings - Use string operations- Describe special characters - Convert strings to numbers and numbers to strings    Useful string operations<jupyter_code># combine strings
first_name_str = 'Ashley'
second_name_str = 'Lee'
full_name_str = first_name_str + second_name_str
print(full_name_str)
space_name_str = first_name_str + " " + second_name_str
print(space_name_str)
# repeat strings
laugh_str = 'ha'
print(laugh_str*3)
# split strings
print(space_name_str)
# split on space
print(space_name_str.split())
print(space_name_str.split(' '))
# split on another character
print(space_name_str.split('l'))
# check if characters are in string
full_name_str = '<NAME>'
chars = 'ash'
check_bool = chars in full_name_str
print(check_bool)
chars = 'Ash'
check_bool = chars in full_name_str
print(check_bool)
# find - returns the first occurrence of a character
print(full_name_str)
print(full_name_str.find('e'))<jupyter_output><empty_output><jupyter_text>Exercise: How would you check if `first_str = 'racecar'` is a palindrome? Assign the check to a variable called `check_pal_bool` and print it.<jupyter_code>first_str = 'racecar'


# write your code above this line
check('tests/lec2_p6.py')<jupyter_output><empty_output><jupyter_text>-  Describe and create characters and strings - Index strings - Use string operations - Describe special characters- Convert strings to numbers and numbers to strings    Special String Characters<jupyter_code>print('first line \n second line')
print('first line \\n second line')<jupyter_output><empty_output><jupyter_text>Exercise: print your first name, a line break, then your last name -  Describe and create characters and strings - Index strings - Use string operations - Describe special characters - Convert strings to numbers and numbers to strings  Casting between types<jupyter_code>print(9 + 5)
print('9' + '5')
print('9' + 5)
print(str(9))
print(type(str(9)))

print(int('9'))
print(type(int('9')))
print(int('9') + 5)
print(float('9.5'))
print(type(float('9.5')))
int('a')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.095881045975047, 'fraction_numerical': 0.007178260126474107, 'mean_word_length': 6.119221411192214, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 1, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '571164', 'license': 'MIT', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1830, 'n_words': 613, 'path': 'week_1/day_2_strings.ipynb', 'repo_name': 'brown-ccv/workshop-python-2020', 'size': '5875'}