New Python user

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Re: New Python user

Post by liuyuan on Wed Oct 01, 2008 6:12 pm
([msg=12972]see Re: New Python user[/msg])

thedotmaster wrote:I disagree.
Firstly that example was just a simple one, a better example would be something where multiple variables are used only once and a new variable is assigned


For give me, but that's exactly why we have different codes to do different things. I made the "for loop" for your simple example. I've never said I would apply it to everything. Same reason why we have ifs/ternary, and switches.

I am however still quite new at python though, if it'd be possible for you to explain why you'd prefer your code over mine with the first example as reference. I did a benchmarking on it, the for loop ran faster than the while loop. It's 3 lines less as well. Can you please explain? thanks :)
ImageImageImage
liuyuan
Experienced User
Experienced User
 
Posts: 64
Joined: Mon Apr 14, 2008 10:17 pm
Blog: View Blog (0)


Re: New Python user

Post by thedotmaster on Thu Oct 02, 2008 1:29 am
([msg=12996]see Re: New Python user[/msg])

liuyuan wrote:
thedotmaster wrote:I disagree.
Firstly that example was just a simple one, a better example would be something where multiple variables are used only once and a new variable is assigned


For give me, but that's exactly why we have different codes to do different things. I made the "for loop" for your simple example. I've never said I would apply it to everything. Same reason why we have ifs/ternary, and switches.

I am however still quite new at python though, if it'd be possible for you to explain why you'd prefer your code over mine with the first example as reference. I did a benchmarking on it, the for loop ran faster than the while loop. It's 3 lines less as well. Can you please explain? thanks :)


You're quite right that a 'for' loop is perhaps a better way of writing my code with the 'while' loop. In running time, it's probably the same, but basically the reason I don't use 'for' loops is because of what we were talking about earlier. When I started learning Python, I just opted for the basics and then moved onto the more interesting stuff. So why bother about various types of loops when one does the same thing? I've managed to sort out a good few of the bad habits I've picked up but this is one of the reasons that I am able to advise people to pay attention to the basics in the first week or two of learning a language.
Tonight I might look up 'for' loops and try and remove that bad habit but whether it'll happen I don't know.
Image
User avatar
thedotmaster
Contributor
Contributor
 
Posts: 984
Joined: Sun May 04, 2008 4:39 pm
Location: North West UK
Blog: View Blog (1)


Re: New Python user

Post by liuyuan on Fri Oct 03, 2008 1:13 pm
([msg=13066]see Re: New Python user[/msg])

^ Ahh, okay, thanks :>

p.s. typo on the word forgive.
ImageImageImage
liuyuan
Experienced User
Experienced User
 
Posts: 64
Joined: Mon Apr 14, 2008 10:17 pm
Blog: View Blog (0)


Re: New Python user

Post by ShadowSniper0819 on Wed Dec 30, 2009 8:55 pm
([msg=32390]see Re: New Python user[/msg])

Jeez, this started as an educational topic...now it's turned into a pissing contest.
There is more than one way to skin a cat, case closed.
ShadowSniper0819
New User
New User
 
Posts: 15
Joined: Thu Dec 10, 2009 3:38 pm
Blog: View Blog (0)


Previous

Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests

cron