Python Forum
Code syntax with underscore and assigning to a tuple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code syntax with underscore and assigning to a tuple
#1
Hi,

I need help in understanding the below syntax.

1)How should I pass the 2nd argument? Should i pass it as 24_2 , where 24 is the current sum and 2 is the counter(keeping the count of numbers).
2)(sum, count) = sum_count - If someone can explain this line it will be helpful.
def add_input(self, sum_count, input):
    (sum, count) = sum_count
    return sum + input, count + 1
Reply
#2
1) It´s a tuple (24,2)
2) Have a look here
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 604 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  Syntax error while executing the Python code in Linux DivAsh 8 1,526 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,196 Jun-19-2023, 03:35 AM
Last Post: 007sonic
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 6,823 Mar-02-2022, 01:23 AM
Last Post: tomtom
  Assigning a new value to variable uriel 1 1,587 Dec-04-2021, 02:59 PM
Last Post: Underscore
  Tuple generator, and function/class syntax quazirfan 3 3,851 Aug-10-2021, 09:32 AM
Last Post: buran
  Even number code syntax error MrCeez 1 2,264 May-02-2021, 06:43 PM
Last Post: Larz60+
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,793 Nov-04-2020, 11:26 AM
Last Post: Aggam
  "SyntaxError: invalid syntax" running code in Doing Math With Python b saucerdesigner 2 2,720 Nov-03-2020, 04:23 PM
Last Post: saucerdesigner
  assigning a variable :( gr3yali3n 0 1,309 Sep-22-2020, 09:02 PM
Last Post: gr3yali3n

Forum Jump:

User Panel Messages

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