Feb-20-2018, 04:33 PM
Pages: 1 2
Feb-20-2018, 04:44 PM
please, post code in code tags, no screenshots/images
Feb-20-2018, 09:04 PM
@volcano
Short answer is because some languages like Python (and Ruby) use whitespace (enter/return) to signify end of lines and new lines. Other languages such as php, javascript, go, c++, etc use semicolons. This is what you're mostly likely thinking of.
In python the colon is necessary after
Also, as of python3, print is a function as
The BBcodes are also super helpful . The ones most commonly used are [(/)python] open(close)tag, [(/)error] open(close) tag.
So you example would look like this:

Short answer is because some languages like Python (and Ruby) use whitespace (enter/return) to signify end of lines and new lines. Other languages such as php, javascript, go, c++, etc use semicolons. This is what you're mostly likely thinking of.
In python the colon is necessary after
if/elif/else/if not:,
with open(filename) as f:,
for:and
while:loops. Your example involves a for loop
for f in foods:. Hence the colon.
Also, as of python3, print is a function as
print('foo')will output
Output:foo
. Also bar = moo print(f'{bar}')outputs
Output:moo
--but this is a slightly advanced topic.The BBcodes are also super helpful . The ones most commonly used are [(/)python] open(close)tag, [(/)error] open(close) tag.
So you example would look like this:
foods = ['bacon','eggs','etc'] for f in foods: print(f) print(len(f))hopefully the admins can amend this post to make its vernacular a bit more pythonic...

Feb-20-2018, 09:23 PM
we are not going to edit your post to make it 'more pythonic'. That is not what we do. However, note that we didn't answer not because we were not able to help, but to make OP post their code according to rules.
Feb-20-2018, 11:12 PM
(Feb-20-2018, 09:23 PM)buran Wrote: [ -> ]we are not going to edit your post to make it 'more pythonic'. That is not what we do. However, note that we didn't answer not because we were not able to help, but to make OP post their code according to rules.
Oops. Sorry. Didn't mean to step on any toes. Meant well. Apologies.
However, it is possible the op didn't know how to use the BBcodes. So I reposted it according to the rules. Just thought it was a pretty good question (from the op's pov).
Feb-21-2018, 04:00 PM
(Feb-20-2018, 09:04 PM)mepyyeti Wrote: [ -> ]@volcano
Short answer is because some languages like Python (and Ruby) use whitespace (enter/return) to signify end of lines and new lines. Other languages such as php, javascript, go, c++, etc use semicolons. This is what you're mostly likely thinking of.
...................
hopefully the admins can amend this post to make its vernacular a bit more pythonic...
Thanks ... You are very helpful and a Python genious for sure . ...Thansks for your help & time man.
This is my first post in the forum !
I have one more question in this regard.
I have C/C++/JAVA & Fortran background. I see "{" ,"}" there . Does python dont use brackets ?
I'm learning this language ..and I dont see brackets in any of the example code. They are mostly using indentation.
I'mnot sure if this language use brackets . Could you please confirm ?
Thanks for the time.
Feb-21-2018, 04:14 PM
python uses indentation to designate blocks of code, not braces.
curly braces denote a dict
if you have a programming background you may check some crash course or this book http://books.goalkicker.com/PythonBook/
curly braces denote a dict
if you have a programming background you may check some crash course or this book http://books.goalkicker.com/PythonBook/
Feb-22-2018, 06:47 AM
(Feb-21-2018, 04:14 PM)buran Wrote: [ -> ]python uses indentation to designate blocks of code, not braces.
curly braces denote a dict
if you have a programming background you may check some crash course or this book http://books.goalkicker.com/PythonBook/

Its very hard to use indentation... Is there any alternative to this ?
Feb-22-2018, 06:51 AM
(Feb-22-2018, 06:47 AM)volcano Wrote: [ -> ]Its very hard to use indentation... Is there any alternative to this ?Well, it's subjective. We think it's very intuitive and results in clean and readable code. There is no alternative.
Pages: 1 2