for loops (python3)

francnstein

francnstein

Posted on April 22, 2020

for loops (python3)

The for loop is commonly used to repeat some code a certain number of times. This is done by combining for loops with range objects.

------------------------------

ex.

for i in range(5):
print("hello!")

------------------------------

  • Now if you wanted to check if the amount of a specific letter within a string.

ex2.

name = 'HEEEELLLLLOO THHERREE'
count = 0
for letter in name:
if letter == 'E':
count = count + 1
print(count)

7

Note: there are easier ways to count letters within a word through built-in tools such as 'HEEEELLLLLOO THHERREE'.count(โ€˜Eโ€™)

                                         FRANCNSTEIN ยฉ | Created ๐—๐—‚๐—๐— โค
๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
francnstein
francnstein

Posted on April 22, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About