1 of 13

Free Python

Class for Girls

Week 3

Mary Xie & Michelle Xie

2 of 13

Reflect

  • What did we talk about last week?
  • What do we remember about strings and floats?
  • What is one thing we remember from last week's class?

3 of 13

What are we learning today?

Today we will learn about what strings are in Python and how we can use them in code!

4 of 13

Think!

What are string?

When do we use strings?

What is the difference between strings and integers or floats?

5 of 13

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:

6 of 13

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!

7 of 13

Concatenation

This means adding strings together

Combines one or more strings into a single string or sequence

8 of 13

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.

9 of 13

Indexing

indexing refers to accessing individual elements in a sequence, in Python, indexing starts at o.

10 of 13

Working with String!

You can print the strings by striping out the beginning and ending whitespaces, print in uppercase, lowercase, or replace a word.

11 of 13

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?”

12 of 13

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

13 of 13

See you next week!