Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pthyon 3 question (newb)
#11
(Feb-26-2019, 06:08 PM)nilamo Wrote: You definitely can.
total = 0
total += 5
total += 1 + 2 + 3 + 4 + 5
print(total) # 20

So you're saying that you can't actually just say += += += +=... you only get to use a single +=. But then, if you do want to daisy chain, you have to just use + by itself. I wonder why they wouldn't put that in the lesson. Probably not to confuse us newbs.

How about this one: In the pic below, why is the aqua colored def the right one? Doesn't that usually mean that something is wrong? Can someone please explain why one def is a different color, and why that one is correct? (once again this is from a code academy lesson)

   
Reply
#12
the first one is invalid syntax and the second one is correct syntax - that is why they are different color. This is feature that will depend on your IDE.

first one has keyword argument (special_item) before positional argument (grocery_store) - that is why it is not correct
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError issue with daughter's newb code MrGonk 2 1,406 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Simple newb string question Involute 2 2,169 Sep-08-2019, 12:50 AM
Last Post: Involute
  please help this newb install pygame iofhua 7 5,849 May-15-2019, 01:09 PM
Last Post: buran
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 2,390 Apr-15-2019, 06:19 AM
Last Post: perfringo
  Newb question about %02d %04d bennylava 30 19,155 Mar-05-2019, 11:23 PM
Last Post: snippsat
  newb selfie PatM 5 3,547 Feb-19-2019, 12:20 AM
Last Post: snippsat
  Complete NEWB and openpyxl project Netopia 44 16,885 Jan-18-2019, 08:15 PM
Last Post: Netopia
  Newb Question - Threading in Crons vvarrior 2 2,730 Jul-20-2018, 08:12 PM
Last Post: vvarrior
  Matt's newb question 1 MattSS102 1 2,670 Aug-28-2017, 03:27 AM
Last Post: BerlingSwe
  Newb: Simple Explicit Formula Duplicitous 1 3,108 May-05-2017, 07:03 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020