Multiple variable declaration
declare multiple variables c
typescript assign multiple variables
I saw this declaration in Python, but I don't understand what it means and can't find an explanation:
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
The question is: why is there there a comma between
thresh? What type of assignment is that?
That's a "tuple" or "destructuring" assignment - see e.g. Multiple assignment semantics.
cv2.threshold returns a tuple containing two values, so it's equivalent to:
temp = cv2.threshold(...) ret = temp thresh = temp
See Assignment Statements in the language reference:
If the target list is a comma-separated list of targets: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets.
C++ Declare Multiple Variables, Declare Many Variables. To declare more than one variable of the same type, use a comma-separated list: Example. int x = 5, y = 6, z = 50; cout << x + y + z;. Python allow you to declare and initialize more than one variable at the time. The syntax is simple but it has some details which are important. You can declare variables without type in Python and you can use them before declaration. Every variable in Python is an object.
This is a value unpacking syntax.
cv2.threshold(imgray,127,255,0) returns a two element tuple.
With this syntax you assign elements of this tuple to separate variables
You can use this syntax to unpack tuples to single variables, e. g.:
a, b = (0, 1) # a == 0 # b == 1
Your code is the same as:
result = cv2.threshold(...) ret = result thresh = result
DCL04-C. Do not declare more than one variable per , Declaring multiple variables in a single declaration can cause confusion regarding the types of the variables and their initial values. If more than one variable is In VBA one can declare more than one variables with a single Dim statement as written below: Dim VAR1, VAR2, VAR3 As Integer. From the above way of declaration, usually we think that all the above 3 variables are declared as “Integer” Type. But this is NOT correct.
SQL SERVER, Method 1: Multiple statements for declaring multiple variables. DECLARE @Var1 INT DECLARE @Var2 INT SET @Var1 = 1. SET @Var2 = 2 You can declare several variables in one statement. To specify a data type, you must include the data type for each variable. In the following statement, the variables intX , intY , and intZ are declared as type Integer .