Python Forum
Learning python specific syntax after using other scripting languages for years
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning python specific syntax after using other scripting languages for years
#8
Also, you can iterate over a str type ( strings ).

So:
for char in 'hello':
    print(char)
Output:
h e l l o
This is the Python way. This is why I love Python. You have seen it in the previous posts I suppose. I really like how some people put an effort to explain something. Bravo to @DeaD_EyE!

A lot of people who comes from other languages are doing this:
s = 'hello'
for char in range( len (s)):
    print(char[0])
It's ugly, clumsy and hard to read. I've seen it in a book teaching Python. Dodgy  Don't remember the title. And in the articles over the web too.

Use the forum to its full potential. Look at the code in the tutorials.

Welcome!
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: Learning python specific syntax after using other scripting languages for years - by wavic - Dec-11-2017, 09:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting days to years in loop while computing values across grid cells Lightning1800 2 2,682 May-15-2018, 08:44 PM
Last Post: Lightning1800

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020