Fiveable
Fiveable
pep
Fiveable
Fiveable

or

Log in

Find what you need to study


3.4 Strings

1 min readjanuary 3, 2023

Minna Chow

Minna Chow

Milo Chang

Milo Chang

Minna Chow

Minna Chow

Milo Chang

Milo Chang

What are Strings?

Strings, as mentioned earlier, are an ordered list of characters. You can navigate through them using index values, just like how you can navigate through a list using index values.

Although you can't perform mathematical operations with strings, you can still manipulate them.

Slicing

A substring is a part of an existing string. For example, "APcomputer" would be a substring of the string "APcomputerscienceprinciples." The process of creating a substring is known as slicing.

There are many different ways to slice a string: here's a basic example.

string_example1 = "APcomputerscienceprinciples"
print (string_example1[0:10])

This code will print the substring "APcomputer". In Python, index values begin at 0, and the character at the end index number (10) is not included.

Here's another example of slicing a string.

string_example2 = "APcomputerscienceprinciples"
print (string_example[2:9])

This code returns the substring "compute".

Concatenation

You can also concatenate strings. String concatenation occurs when two or more strings are joined end to end to make a new string. This is usually represented by the + symbol.

part_one = "Hello"
part_two = "_World!"
print (part_one + part_two)

The code returns:

Hello_World!

Key Terms to Review (2)

Concatenation

: Concatenation refers to combining two or more strings together to create a new, longer string.

Substring

: A substring is a smaller portion of a larger string extracted based on its starting and ending positions within that string.

3.4 Strings

1 min readjanuary 3, 2023

Minna Chow

Minna Chow

Milo Chang

Milo Chang

Minna Chow

Minna Chow

Milo Chang

Milo Chang

What are Strings?

Strings, as mentioned earlier, are an ordered list of characters. You can navigate through them using index values, just like how you can navigate through a list using index values.

Although you can't perform mathematical operations with strings, you can still manipulate them.

Slicing

A substring is a part of an existing string. For example, "APcomputer" would be a substring of the string "APcomputerscienceprinciples." The process of creating a substring is known as slicing.

There are many different ways to slice a string: here's a basic example.

string_example1 = "APcomputerscienceprinciples"
print (string_example1[0:10])

This code will print the substring "APcomputer". In Python, index values begin at 0, and the character at the end index number (10) is not included.

Here's another example of slicing a string.

string_example2 = "APcomputerscienceprinciples"
print (string_example[2:9])

This code returns the substring "compute".

Concatenation

You can also concatenate strings. String concatenation occurs when two or more strings are joined end to end to make a new string. This is usually represented by the + symbol.

part_one = "Hello"
part_two = "_World!"
print (part_one + part_two)

The code returns:

Hello_World!

Key Terms to Review (2)

Concatenation

: Concatenation refers to combining two or more strings together to create a new, longer string.

Substring

: A substring is a smaller portion of a larger string extracted based on its starting and ending positions within that string.

Fiveable
About Us

About Fiveable

Blog

Careers

Code of Conduct

Terms of Use

Privacy Policy

CCPA Privacy Policy

Resources

Cram Mode

AP Score Calculators

Study Guides

Practice Quizzes

Glossary

Cram Events

Merch Shop

Crisis Text Line

Help Center

Stay Connected


© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

About Us

About Fiveable

Blog

Careers

Code of Conduct

Terms of Use

Privacy Policy

CCPA Privacy Policy

Resources

Cram Mode

AP Score Calculators

Study Guides

Practice Quizzes

Glossary

Cram Events

Merch Shop

Crisis Text Line

Help Center

© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.