7 ms·
Not only that, he's wrong - Python is sensitive to indentation, not whitespace. As long as your block is at the right depth, you can have as much whitespace as
by gaius 17y ago
Not only that, he's wrong - Python is sensitive to indentation, not whitespace. As long as your block is at the right depth, you can have as much whitespace as you want. I regularly format code so similar things line up. This is perfectly valid Python:
def foo():
longvariable = 1
x = 2
Also on the subject of lambdas, this is also valid:
def foo():
def bar(x):
return x + 5
print bar(5)
With a nice clean syntax for nested functions, lack of multi line lambdas is much less of an issue.
- yannis 17y agoThis reminds me of my high school algebra teacher. He would automatically fail you in tests if your equals did not line up. Very neat syntax!
- jacquesm 17y agoInteresting how your variable example is pretty much straight against the python styleguide: http://www.python.org/dev/peps/pep-0008/ http://www.python.org/dev/peps/pep-0008/ I'd do it just like you do though. I find it visually harder to fish those equals signs out of the 'noise' otherwise.
- deleted 17y ago[deleted]
- gaius 17y agoIn the wild, you're more likely to find Python that looks like: longvariable, x = 1, 2 However this won't work: longvariable, x = 1, foo(longvariable) So I like to keep things uniform regardless of the rvalue. Also violating the style guide, I like longvariable = "hello" # some description of longvariable x = 1 # some descrption of x
- JshWright 17y agoTo give an example in reply to the Clojure snippet that is now mysteriously missing from the article (to demonstrate something Python users should be jealous of)... This is perfectly valid in Python: users = [ # Name ID Age Phone ['John', 5, 37, '555-1234'], ['Bill', 5, 29, '555-4321'], ['Jean', 5, 32, '555-4132'], ] Edit: Always a good idea to test even the simplest snippets before posting them...
- jacquesm 17y agoTell me about it :) Three lines, 5 bugs I think is my record to date.