Threadser.net
數據
關鍵字
功能建議
Following
Threads
Login
串文
串文鏈結
2024-10-31 17:37
My son is learning Python. I'm a C#, PHP, JAVASCRIPT guy and really struggle with code blocks in Python. Brackets just make it easier for me to "see". as in if( a==b ) { do things here }
讚
124
回覆
162
轉發
作者
Todd
toddinsnellvegas
粉絲
串文
101+
讚
回覆
轉發
24小時粉絲增長
無資料
互動率
(讚 + 回覆 + 轉發) / 粉絲數
Infinity%
回覆 (BETA)
最先回覆的內容
發文後
用戶
內容
3 小時內
John Bigg
gasteropod
If I'm testing, adding code temporarily, or trying something out, I left justify out of indentation so it's obvious. Can't do that with python. Haven't come up with a good alternative.
4 小時內
Leighton Lee
lovewillb4u
I’m going to be that guy and say you should put the opening bracket after the parenthesis and indent the code in your brackets. Having brackets does make it easier to tell where your block of code is but you should still write clean code. (Unless you only write JavaScript because everyone gave up on writing clean code there)
10 小時內
Paul Winter
paulbme2
I think that he's learning that programming languages require some form of structure to define a block of code. Python does it with : and space indentation, c and other languages use braces {} , pascal uses begin and end; The important part is know what you are defining a block of code for.
13 小時內
Pauldo
morpheus202402
You just have to imagine brackets are there to enclose a code block.
13 小時內
Joshua Ohm
jaydo.pnw
4 spaces or more per tab in python might help a lot.
一天內
gonoph
gonoph
I’m a C, C++, Java dev myself, and I enjoy the ease of coding in Python. It does take a bit of mental conditioning to go from more procedural languages to more a functional language. Python’s indentation style persuades you to make smaller functions/classes, use closures, eyeball recursion, and put things into multiple smaller files. Learning additional language patterns and syntax has helped my coding in other languages by using those skills to look at problems a little differently.