Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Strings & Formatting | Basic Syntax
Introduction to Python with Cursor

bookStrings & Formatting

What Is a String?

A string (str) is a sequence of characters enclosed in quotes. It can hold names, messages, sentences, symbols, or even be empty.

In Python, you can use:

  • Single quotes: 'hello';
  • Double quotes: "hello".

Both forms work the same way.

Multiline strings

Sometimes, you need to write text that spans several lines β€” like a paragraph or a message. For this, Python uses triple quotes:

  • '''...''';
  • """...""".

These preserve line breaks and spacing.

String Formatting

Sometimes you need to insert values into a string, such as names, numbers, or results. Python supports several formatting methods, but the most common and readable is the f-string.

f-Strings

With an f-string, you place variables or expressions inside {} directly in the text. Add the letter f before the opening quote to enable this feature.

Summary

  • Strings in Python are written using quotes β€” single or double;
  • Triple quotes are used for multiline text;
  • f-strings allow dynamic values to be inserted into strings.
question mark

What will the expression "Python".lower() return?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 5

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you show more examples of strings with different types of quotes?

What happens if I mix single and double quotes in a string?

Are there any special characters I need to escape in Python strings?

Awesome!

Completion rate improved to 5

bookStrings & Formatting

Swipe to show menu

What Is a String?

A string (str) is a sequence of characters enclosed in quotes. It can hold names, messages, sentences, symbols, or even be empty.

In Python, you can use:

  • Single quotes: 'hello';
  • Double quotes: "hello".

Both forms work the same way.

Multiline strings

Sometimes, you need to write text that spans several lines β€” like a paragraph or a message. For this, Python uses triple quotes:

  • '''...''';
  • """...""".

These preserve line breaks and spacing.

String Formatting

Sometimes you need to insert values into a string, such as names, numbers, or results. Python supports several formatting methods, but the most common and readable is the f-string.

f-Strings

With an f-string, you place variables or expressions inside {} directly in the text. Add the letter f before the opening quote to enable this feature.

Summary

  • Strings in Python are written using quotes β€” single or double;
  • Triple quotes are used for multiline text;
  • f-strings allow dynamic values to be inserted into strings.
question mark

What will the expression "Python".lower() return?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 5
some-alt