Video of looping through strings

in the following code:

     for letter in fruit:

How does computer know that the word ‘letter’ is the letter that we know? because we haven’t defined anything then How can python print the letters of banana?

It doesn’t, you can put whatever you wanted instead of “letter”, you could have put just a single letter and it would work. In this loop, the computer is assigning a variable called “letter” for each letter in your word and reading it. Name doesn’t matter as long as you have put some kind of value :slight_smile:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Ohk…got it.
Thank you so much

1 Like

I strongly advise you follow the FCC curriculum on Scientific Computing with Python, which is represented by the free course Python for Everybody by Dr. Charles Severance and one of the things he puts as sideline emphasis is naming conventions, or the lack of such, when it comes to computers

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.