Зміст курсу
String Manipulation in Python
String Manipulation in Python
Counting
Let's consider some other methods that can be applied to strings. One of them can help us count the number of appearances of some symbol/substring within a string.
To count the number of symbol/substring in string use .count(symbol/substring)
method. For example,
string = "String Manipulation in Python" print("letter i appeared", string.count('i'), "times in the string.") print("letter t appeared", string.count('t'), "times in the string.")
Note
This method is case-sensitive to symbols. For the example above,
string.count('m')
will return 0, whilestring.count('M')
will return 1.
Завдання
You are given string
"Introduction to Python". You need to calculate the number of symbols 'o'
and 't'
in this string.
Дякуємо за ваш відгук!
Counting
Let's consider some other methods that can be applied to strings. One of them can help us count the number of appearances of some symbol/substring within a string.
To count the number of symbol/substring in string use .count(symbol/substring)
method. For example,
string = "String Manipulation in Python" print("letter i appeared", string.count('i'), "times in the string.") print("letter t appeared", string.count('t'), "times in the string.")
Note
This method is case-sensitive to symbols. For the example above,
string.count('m')
will return 0, whilestring.count('M')
will return 1.
Завдання
You are given string
"Introduction to Python". You need to calculate the number of symbols 'o'
and 't'
in this string.
Дякуємо за ваш відгук!
Counting
Let's consider some other methods that can be applied to strings. One of them can help us count the number of appearances of some symbol/substring within a string.
To count the number of symbol/substring in string use .count(symbol/substring)
method. For example,
string = "String Manipulation in Python" print("letter i appeared", string.count('i'), "times in the string.") print("letter t appeared", string.count('t'), "times in the string.")
Note
This method is case-sensitive to symbols. For the example above,
string.count('m')
will return 0, whilestring.count('M')
will return 1.
Завдання
You are given string
"Introduction to Python". You need to calculate the number of symbols 'o'
and 't'
in this string.
Дякуємо за ваш відгук!
Let's consider some other methods that can be applied to strings. One of them can help us count the number of appearances of some symbol/substring within a string.
To count the number of symbol/substring in string use .count(symbol/substring)
method. For example,
string = "String Manipulation in Python" print("letter i appeared", string.count('i'), "times in the string.") print("letter t appeared", string.count('t'), "times in the string.")
Note
This method is case-sensitive to symbols. For the example above,
string.count('m')
will return 0, whilestring.count('M')
will return 1.
Завдання
You are given string
"Introduction to Python". You need to calculate the number of symbols 'o'
and 't'
in this string.