Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте String Length | Рядки
Типи даних у Python

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

book
String Length

Сalculating the number of characters in a string is a common operation. It helps in tasks like validation, formatting, or data analysis. Python provides a built-in function len() to get the length of a string.

python

The string parameter refers to the text whose length you want to determine; the len() function returns the total number of characters in that text, including spaces and punctuation marks.

12345
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
copy

The len() function counts every character in the string, including spaces. In the example, "Practice is the key to success" has 31 characters, so len(text) returns 31.

Завдання

Swipe to start coding

Time to practice:

  1. Get the last character of the variable string using negative indexation and assign the result to the variable symbol1.
  2. Extract the index of the last character of the variable string using the len() method and assign the result to the variable symbol2.

Note that len(word) equals the length of the word, but len(word)-1 equals the index of the last character of the word.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

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

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

Секція 3. Розділ 8

Запитати АІ

expand
ChatGPT

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

book
String Length

Сalculating the number of characters in a string is a common operation. It helps in tasks like validation, formatting, or data analysis. Python provides a built-in function len() to get the length of a string.

python

The string parameter refers to the text whose length you want to determine; the len() function returns the total number of characters in that text, including spaces and punctuation marks.

12345
string = "Practice is the key to success" length = len(string) print("Here is the string:", string) print("And its length is", length)
copy

The len() function counts every character in the string, including spaces. In the example, "Practice is the key to success" has 31 characters, so len(text) returns 31.

Завдання

Swipe to start coding

Time to practice:

  1. Get the last character of the variable string using negative indexation and assign the result to the variable symbol1.
  2. Extract the index of the last character of the variable string using the len() method and assign the result to the variable symbol2.

Note that len(word) equals the length of the word, but len(word)-1 equals the index of the last character of the word.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

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

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

Секція 3. Розділ 8
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Ми дуже хвилюємося, що щось пішло не так. Що трапилося?
some-alt