Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Strings & Formatting | Basic Syntax
Introduction to Python with AI

bookStrings & Formatting

Note
Example Prompts
  • What is a string in Python? How do I write one with single or double quotes? Show code example.
  • How do I create a multiline string in Python? Provide code example.
  • How do f-strings work in Python? Explain with examples.
  • Make short cheatsheet for "Strings & Formatting" topic.

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.

Task

  1. Write a short greeting using a name stored in a variable.

  2. Try to format it using an f-string.

    For example: if the name is "Alex", the program should display a personalized message.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you show me an example of how to use an f-string with a variable?

What happens if I forget the 'f' before the string?

Can I use f-strings with numbers or only with text?

Awesome!

Completion rate improved to 5

bookStrings & Formatting

Свайпніть щоб показати меню

Note
Example Prompts
  • What is a string in Python? How do I write one with single or double quotes? Show code example.
  • How do I create a multiline string in Python? Provide code example.
  • How do f-strings work in Python? Explain with examples.
  • Make short cheatsheet for "Strings & Formatting" topic.

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.

Task

  1. Write a short greeting using a name stored in a variable.

  2. Try to format it using an f-string.

    For example: if the name is "Alex", the program should display a personalized message.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5
some-alt