Questions tagged [variable-assignment]

A process of setting or re-setting the value stored in the storage location(s) denoted by a variable name.

4336 questions
1
vote
3 answers

How do you (get around) dynamically naming variables?

I'm not sure if I'm using the right nomenclature, so I'll try to make my question as specific as possible. That said, I imagine this problem comes up all the time, and there are probably several different ways to deal with it. Let's say I have an…
jefflovejapan
  • 2,047
  • 3
  • 20
  • 34
1
vote
3 answers

Iterate 2D arrays and assignment to variables of function in python

I am new to Python. I have a 2D array (10,4) and need to iterate array elements by assigning four values of each row to four variables of function (x1, x2, x3, x4), and return function output. Please have a look at my code and give me suitable…
Husnain
  • 243
  • 1
  • 2
  • 5
1
vote
1 answer

How to initialize a variable that will eventually be set to the response of an async request in Typescript?

Being relatively new to typescript, I've run into a problem that I didn't face in my first project - when declaring a variable prior to an api request inside a try-catch seems to throw typescript errors for operations on this variable after the…
Darkphoton
  • 506
  • 4
  • 14
1
vote
1 answer

(VERI-1322) prefix of assignment pattern must be a data type

Here is a snippet from my code; always_ff @(posedge clk) begin : output_assigment // left side should only be "_q" if(reset_n == 1'b0 || clear == 1'b1) out_signal_q <= {8'{!(REPORT_POL)}}; But i see this error: (VERI-1322) prefix of…
Nisha John
  • 25
  • 3
1
vote
1 answer

Assignments in for loops

This is something I wish to ask on top of the question that is already discussed: Assigning values to variables in a list using a loop So the link above says it is not recommended to perform assignments in a for loop because doing so changes only…
Robin311
  • 203
  • 1
  • 9
1
vote
1 answer

In Kotlin, Why can the value of a val integer be reassigned by the inc() method?

Consider the following, val x: Int = 0 val variables cannot be changed so doing x += 1 wouldn't work The compiler says Val cannot be reassigned why then does x.inc() work fine doesn't x.inc() reassign the value from 0 to 1
Ser.T
  • 51
  • 4
1
vote
3 answers

Java comparing two strings doesnt seem to work

I got this function which is a private boolean function that checks if there is a car already of the same size inside the garage. If there isn't I add it to the arrayList, I've made a printList() type function before to traverse through the…
FHr
  • 141
  • 1
  • 2
  • 10
1
vote
1 answer

Is it possible to dynamically assign an array of structs in C?

In a project I'm working on, I find myself creating a lot of small, hand-written arrays of structs that need to be stored in dynamically allocated memory (mostly for testing with small datasets before importing from a file). There's a really nice…
catlover2
  • 251
  • 2
  • 15
1
vote
2 answers

Joining strings except empty ones in javascript

I was wondering what is the best way to join a few strings in javascript except if they are empty. Say we have let s1 = 'X = 1'; let s2 = ''; let s3 = 'Z = 3'; And my end result need to be "X = 1, Z = 3" let str = [s1,s2,s3].join(',') // will…
Clothahump
  • 47
  • 5
1
vote
0 answers

How to let a solver in pyomo assign a Var array of Integers

Suppose I have a status array, where each status is within the integer domain, how can I utilize pyomo to assign the individual cells appropriately? In the following snippet I simplified this by enforcing the solver to assign fixed values taken from…
frunk
  • 15
  • 4
1
vote
1 answer

Initialize nontrivial class members when created by PyObject_NEW

I have a Python object referring to a C++ object. Header: #define PY_SSIZE_T_CLEAN #include #include typedef struct { PyObject_HEAD FrameBuffer frame_buffer; } PyFrameBuffer; extern PyTypeObject…
Narann
  • 819
  • 2
  • 8
  • 20
1
vote
0 answers

Python function print output redirect

Its my first attempt at coding and I've a bit of a snag. I was wondering if one of you would be able to point me in the right direction for this case.. What I'm trying to do is convert a string from hexadecimal format into readable text. Following…
1
vote
2 answers

Pass data frame and reference it for assignment inside function in R

I'm getting tripped up on assigning after passing a data frame through a function. The real function is much larger but below is an example. The goal: If the quarter column name is in the active_quarters vector, do nothing. If it isn't, assign…
Ian Hunter
  • 35
  • 5
1
vote
1 answer

Typescript: Return a reference object that can be assigned to?

I have an existing set of classes that have a number of spots where they get, and one spot where they set, a named property from an array, i.e. return object[index]; // or object[index] = newValue; Due to one existing module that does things…
Trevortni
  • 688
  • 8
  • 23
1
vote
1 answer

What is so special about += operator?

I wrote a code similar to the following and it gives me the local variable 'a' referenced before assignment error. When I changed that a += [2] into a.append(2), it worked. def f(): a = [1] def f1(): a += [2] # => no error with…
moon
  • 531
  • 1
  • 5
  • 24
1 2 3
99
100