Learning Python: efficiency question
I'm new to Python and a beginner at programming in general.
Is there an efficiency difference between Code A and Code B?
I would think so, yes.
1. Code A is calling len() a lot more. At worse, you're calling it 3 times. If the string is quite large, it'd be quite inefficient.
2. Code A has more conditions.
That's all I an think of.
Code B is better, for all the reasons posted above. It also shows better logic, through your use of 1 return of s.
But, the code does slightly different things. Code A won't append anything to s if s is = to 3, whereas Code B will. Is this a mistake?
|All times are GMT +1. The time now is 01:23 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.