11title: Basic Data Types in Python 3: Strings
22slug: python-basic-data-types-strings
3- meta: Learn to create and manipulate strings in this series of blog posts on basic data types in Python programming
3+ meta: Learn to create and manipulate strings in this series of blog posts on basic data types in Python programming.
44category: post
55date: 2019-10-18
66modified: 2019-10-18
77newsletter: False
8- headerimage: /img/191018-python-basic-data-types-strings/header.jpeg
8+ headerimage: /img/191018-python-basic-data-types-strings/header.jpg
99headeralt: Learn basic Python data types in TwilioQuest 3 - Strings
10+ author: Kevin Whinnery
11+ authorlink: https://www.twilio.com/quest
1012
11- If you're [ new to the language] ( https://wiki.python.org/moin/BeginnersGuide/Overview ) ,
12- there's a lot to learn on your Python journey. Once you're comfortable writing
13- and executing code, your first stop becomes learning how to represent data in
13+
14+ There is a lot to learn on your Python journey when you are
15+ [ new to the programming language] ( /learning-programming.html ) . Once you are
16+ comfortable writing and executing code, your first stop becomes understanding
17+ how to represent data in
1418your code. No matter the language, there are a few basic data types you'll use
1519all the time - strings, numbers, booleans, lists, and dictionaries.
1620
@@ -23,8 +27,8 @@ You'll learn about basic data types and much more about Python programming.
2327
2428Ready to learn how to use strings in Python 3? Let's get started!
2529
26- ## Strings in Python 3
2730
31+ ## Strings in Python 3
2832One of the most common data types in any programming language is a ` string ` . A
2933__ string__ represents a series of characters, which you would use to represent
3034usernames, blog posts, tweets, or any text content in your code. You can create
@@ -34,8 +38,8 @@ a string and assign it to a variable like this.
3438my_name = " Jonathan Joestar"
3539```
3640
37- ### Strings are "immutable"
3841
42+ ### Strings are "immutable"
3943In Python, strings are considered [ immutable] ( https://www.merriam-webster.com/dictionary/immutable ) -
4044once you create them, they can't be changed. You can, however, use a variety of
4145methods to create new strings from existing strings. This type of work in
@@ -45,8 +49,8 @@ far from the truth!
4549
4650Here are some common tasks you might undertake when using strings in your code.
4751
48- ### Common task - combining strings together
4952
53+ ### Common task - combining strings together
5054Combining strings together - __ concatenating__ them - is a very common task. In
5155Python 3, you can use the ` + ` operator for this purpose. You can use the ` + `
5256operator multiple times to concatenate multiple strings.
@@ -58,8 +62,8 @@ last_name = "Joestar"
5862full_name = first_name + " " + last_name
5963```
6064
61- ### Common task - inserting data into strings
6265
66+ ### Common task - inserting data into strings
6367Another common task with strings is inserting data into a specific place
6468within a string. In programming, we call this __ string interpolation__ . Python 3
6569provides a handy tool for doing this called [ "f" strings] ( https://www.python.org/dev/peps/pep-0498/ ) .
@@ -81,8 +85,8 @@ message = f"My name is {first_name} {last_name}, and I am {age} years old."
8185print (message)
8286```
8387
84- ### Common task - using built-in string methods to manipulate strings
8588
89+ ### Common task - using built-in string methods to manipulate strings
8690String objects have a number of [ methods] ( https://docs.python.org/3/library/stdtypes.html#string-methods )
8791to perform common tasks, like changing the case of strings or trimming their
8892content. Below, you'll find a few examples. In two of these examples, we are
@@ -122,8 +126,8 @@ for item in groceries:
122126[ Check our more strings can do] ( https://docs.python.org/3/library/stdtypes.html#string-methods )
123127in the Python 3 docs!
124128
125- ## Type casting
126129
130+ ## Type casting
127131Frequently, you will want to convert data from one type into another. In
128132programming, we call this process __ type casting__ . There are a number of
129133__ functions__ built in to Python which allow us to do these type conversions
@@ -145,12 +149,14 @@ converted = int(example_string)
145149message = f " Two plus two equals { converted + 2 } "
146150```
147151
148- ## Wrapping up
149152
153+ ## Wrapping up
150154Strings of text are one of the most common pieces of data you will work with
151155in programming. Hopefully, you've learned a bit about how to work with strings
152156in Python 3! Stay tuned for more blog posts in this series to learn more about
153157basic data types like strings, numbers, booleans, lists, and dictionaries.
154158
155- Also, be sure to [ download and play TwilioQuest 3] ( https://www.twilio.com/quest/download )
156- to learn even more about the Python programming language!
159+ Also, be sure to
160+ [ download and play TwilioQuest 3] ( https://www.twilio.com/quest/download )
161+ to learn even more about Python!
162+
0 commit comments