Free Python
Class for Girls
Week 3
Mary Xie & Michelle Xie
Reflect
What are we learning today?
Today we will learn about what strings are in Python and how we can use them in code!
Think!
What are string?
When do we use strings?
What is the difference between strings and integers or floats?
What is a string?
A string is a sequence of characters enclosed in either single quotes ('') or double quotes (“”), used for representing textual data
Ex:
Immutable Strings
-Python strings are "immutable" which means they cannot be changed after they are created.
-However there are ways for us to change or add things into strings!!
-We will talk about Concatenation, Slicing, and Indexing!
Concatenation
This means adding strings together
Combines one or more strings into a single string or sequence
Slicing
This is the operation of extracting a portion of the sequence. It is done using the colon operator. The syntax is "startstopstep".
"Start" is the index of the first element" to include, "stop" is the index of the first element you want to exclude, and "step" is the step size between elements. If any is omitted, if defaults to the beginning, the end,and a step size of 1.
Indexing
indexing refers to accessing individual elements in a sequence, in Python, indexing starts at o.
Working with String!
You can print the strings by striping out the beginning and ending whitespaces, print in uppercase, lowercase, or replace a word.
Practice!
String_1 = “Hi”
String_2 = “How are you”�String_3 =“I’m good.”
String_4 = “?”
String_5 = “!”
Use CONCATENATION to write “Hi! How are you?”
CHECK YOUR ANSWER
String_1: “Hi”
String_2: “How are you”�String_3: “I’m good.”
String_4: “?”
String_5: “!”
String_1 + String_5 + “ “ + String_2 + String_4
See you next week!