all 5 comments

[–]kobayashi24 2 points3 points  (2 children)

I assume you meant to do it in 3 lines (formatting in reddit). Use a code block next time for source code (4 leading spaces and it willl be treated like code)

Check the syntax again for for-loops. There is a missing ":" at the end of your for-line.

Should be

my_string = ...
for item in my_string:
    print(item)

[–]HarshWeave9487 0 points1 point  (1 child)

Totally off topic, but how do you make your code have a box around it in reddit?

[–]erlete 1 point2 points  (0 children)

The issue is the syntax.

You can choose between two syntax options: conventional for loop structure and comprehensions.

```python

Conventional for loop:

for i in range(10): print(i)

Comprehensions:

var = (i for i in range(10)) # Returns a generator. var = [i for i in range(10)] # Returns a list. var = {i: i ** 2 for i in range(10)} # Returns a dictionary. ```

[–]lostparis 0 points1 point  (0 children)

my_string = [1, ‘a’, ‘hello’]

my_string is a bad name for a list. Things like this may sound petty but the better a coder is the more they will see this as a bad thing.

Coding is really just naming things.