Python questions from C/Perl/Java programmer
William Park
parkw at better.net
Mon Jul 24 12:53:07 EDT 2000
On Mon, Jul 24, 2000 at 12:31:05PM -0400, ye, wei wrote:
> 1. Why not use {}?!
> def f:
> ...
> why not use {} like this:
> def f {
> ...
> }
Usual answer is '{}' uses up extra line. But, Guido decided on this
long time ago and is unlikely to change his mind.
> The other problem is if you want to added a new condition in a complex
> already existed condition statement,
> e.g. In the following example, If you want to added a new 'if' between
> line 1 and 2, you have to add TAB from Line 2 to 199,
> it's difficult to make sure you don't make mistake. (The case may be
> more complex as the example which I give).
>
> 1 if() :
> 2 if():
> 3 ....
> ....
> ....
> 100 else:
> ...
> 200else :
> ...
If you have to manually type 200 if-then-else, then perhaps you
re-examine your logic. However, indentation should be taken care of by
your editor. I use 'vim' with
au BufRead *.py set smartindent
au BufRead *.py set cinwords=if,elif,else,for,while,try,except,finally,def,class
to get automatic indenting for the first line. More recent 'vim' may
have other features that I'm not aware of.
> 2. Why variable doesn't have to be declared before use?
The usual answer is "because it's Python".
More information about the Python-list
mailing list