Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Зберігання Тексту | Змінні та Типи
Вступ до Python
course content

Зміст курсу

Вступ до Python

Вступ до Python

1. Перше Знайомство
2. Змінні та Типи
4. Інші типи даних
5. Цикли
6. Функції

book
Зберігання Тексту

У першій главі ви дізналися, як виводити повідомлення "Hello world!" у Python. Це повідомлення називається string (рядок). У Python рядки використовуються для зберігання тексту, який також може містити числа.

12345
# Save string within variable language = 'Python' # Output string print(language)
copy

Variables that store text are known as strings. A string is a sequence of characters used to represent text in Python. Strings are enclosed in either single quotes (') or double quotes (").

Although strings can contain numbers, they are treated as text, meaning you cannot perform mathematical operations on them directly. To use a number stored as a string in calculations, you need to convert it to a numeric type first.

123
hour = '16' print(hour)
copy

Якщо ви хочете перетворити об'єкт у рядковий тип, використовуйте функцію str().

123456789
# Using double quotes outside message = "It's a beautiful day!" # Using single quotes outside greeting = 'He said, "Hello!"' # Use \ to escape single quote inside single-quoted string message = 'It\'s a beautiful day!' # Use \ to escape double quote inside double-quoted string greeting = "He said, \"Hello!\""
copy
What is a string in Python?

What is a string in Python?

Виберіть правильну відповідь

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

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

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

Секція 2. Розділ 6
We're sorry to hear that something went wrong. What happened?
some-alt