Advancing in Data Science, One Byte at a Time!

DataScience Ville Logo
Search
Close this search box.

3 Ways of Writing Strings in Python!

python strings
Python strings

Strings are the basics of the basics when learning Python.

They’re basically any value (including alphabets, numbers, special characters, etc.) that’s placed within quotes (“ ”)

You probably never knew there was a term for it before learning Python. And depending on the level of Python knowledge you have, you also know that there’s more to uncover about Strings.

This ranges from the different ways of writing them to their relationship with other data types like integers and floats.

To start, this post will focus on the three basic ways of writing strings.

1. Double Quote Strings

This is the most common way of writing strings in Python. It’s the method I’ve seen programmers use the most:

That said, I’m a fan of the next method:

2. Single Quotes

However, using single quotes puts you in a weird situation when you need to include an apostrophe within your strings.

For double quotes, you can simply write:

But of course, there’s a way around it. If not, this wouldn’t even be a method of writing strings.

All you need to do is make use of the backslash (\):

Though, since it’s confusing, it’s clear to see why many would opt for the first method especially when you’re working on an intense project.

3. Triple Quotes

Triple quotes give you more flexibility than the other two. It allows you to even make simple designs as strings.

But these are just the basics of the basics when it comes to strings in Python. In the next post, we’ll take a closer look at the relationship between strings (anything within a quote) and data types like integers and floats.

Recent Posts

Subscribe for Regular Updates

 Get Insightful News on Data-related Topics

SUBSCRIBE FOR REGULAR UPDATES

Discover more from Kester R. on a wider range of topics here on: