Comments are the sole responsibility of the person posting them. You agree not to post comments that are off topic, defamatory, obscene, abusive, threatening or an invasion of privacy. Violators may be banned. Click here for our full user agreement.
rockymountainnews.com
Tags: getting,
ice,
lyrics,
thinner
That’s usually a case of mixed tabs and spaces.Fun stuff.
If you divide two numbers in today’s Python, the result is a number of the same type.In practice, it’s not5/2that’s the problem, but things like:def func(a, b, c): return (a + b) / 2 + … more stuff …which works well in initial testing with floats, and suddenly starts misbehaving when someone passes in an integer to some function that calls “func” two years later.To avoid this, use:def func(a, b, c): return float(a + b) / 2 + …permalinkparentnotfancy (0 children) [+]notfancy 6 points 4 months ago [-]That’s why I always prefer to write 0.5 * (a + b).
Your second nit is actually possible, it’s just a bit weird and rarely useda = b and c or dis the same as the C-isha = b ? c : dalso this worksif a: foo()else: bar()I’m not familiar with what is meant by implicit return but all functions return a value. If you don’t specify a return value, None is implicitly returned.
It is integer division. Doesn’t mean the result is an integer.
A cool quirk that I use is list expansion. Say you have:def afunc(a, b, c): passAnd you have a list:alist = [x, y, z]You can pass alist into afunc with:afunc(*alist)Very nice. There are probably 10 other niceties I could come up with.
coder beware I guess.
It may be common, but it’s still weird. The forward slash should perform division in the mathematical sense, some other operator should do the odd auto-truncating division (same thing goes for integer arithmetic with overflows).
A messy one line if/case structure, which will probably work in your Jython environment:(’FizzBuzz’,’Buzz’,’Fizz’,str(i))[bool(i%3)+2*bool(i%5)]You can embed functions inside lists/tuples/dictionaries, allowing for all sorts of horrible abuses. Want to make a really simple code parser? Dictionaries of functions can be used to make a sanitized/crippled eval.Being python, these hacks do not work for recursion. So the less ugly and seemingly harmlessfac = lambda n: [1, n*fac(int(n)-1)][n>1]should not be run.
Is is used for checking if two objects reference the same one and not for equality. I don’t see the issue.