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

I get different output when printing a matrix of char

I'm trying to program the game Minefield. I think the best way to make the field is to use a matrix of char. I ask the user for the difficulty, fill the matrix and then output the result just to see if that worked, but it doesn't, here's the…
1
vote
1 answer

Python Array variable assignment

I am newbie to python so having difficulty understand this code behavior for scenarios listed below. I can understand the first 3 where the output is a=[1], b=[0] but in the last case why is the value of b getting changed to [1] ? a = [0] b = a[:] a…
OhMoh24
  • 41
  • 6
1
vote
0 answers

Is it possible to use a destructuring assignment for an array of objects?

Say I have the following: const db = {players: [{elo:3}, {elo:4}]} I can do this const [white, black] = db.players But what if I want to get the elo fields? I can do this: const [{elo:elo1}, {elo:elo2}] = db.players It would be cleaner to combine…
Jeff Lowery
  • 2,492
  • 2
  • 32
  • 40
1
vote
5 answers

In C#, How can I create or overload an assignment operator to possibly assign two values at once?

This is probably a stupid question, but just in case.... We have a 3rd party package with weird models like: public partial class CountingDevice { public int countingDeviceNo { get; set; } public string countingDeviceName { get; set; } …
1
vote
3 answers

Incremental Assignment

I have been working with C++ for many years, but just realized something fishy about incremental assignment. I have this snippet a = 4; b = 2; c = 0; c = c + a > b; printf("a: %d\tb: %d\tc: %d\n",a,b,c); c = c + a > b; printf("a: %d\tb:…
Sriram Murali
  • 5,804
  • 2
  • 26
  • 32
1
vote
2 answers

How to create a variable with error going to /dev/null

I am not able to redirect an expected error to &>/dev/null in the following simple code. xml=`ls ./XML_30fps/*.xml ./XML_24fps/*xml` The expected error is due to the fact that one of the folders could be empty and so the error would be "No such…
Robin
  • 339
  • 1
  • 9
1
vote
3 answers

What's the difference between using an Assignment Constructor vs. normal assignment here?

I've spent some time trying to understand some C++ code, and I have background in C and Java. The code in question used what looked to be shorthand of some kind that I didn't recognize or understand for some time. I know now that they were using…
Chthonic One
  • 213
  • 3
  • 11
1
vote
2 answers

Why do I need trailing comma in multiple assignment / unpacking?

CASE 1 code in below works well d, c, b, *a = 5, 4, 3, 1, 2 print(type(a), a) print(type(b), b) print(type(c), c) print(type(d), d) Results [1, 2] 3 4 5 CASE 2 But as soon as i…
Sachin84
  • 47
  • 8
1
vote
0 answers

how can i use destructuring inside a class in javascript

I want to use "destructuring assignment" inside of a class function to get ride of using "this" keyword multiple time... but i got this error: Uncaught ReferenceError: a is not defined my code is somthing like this: class className { …
1
vote
1 answer

Creating ID for every row based on the observations in variable

A want to create a system where the observations in a variable refer to a number using Python. All the numbers from the (in this case) 5 different variables together form a unique code. The first number corresponds to the first variable. When an…
1
vote
2 answers

Python ValueError: could not convert string to float: '1,000000E+06'

I have a list of around 70 string values, all of them with the E+(05 or 06), which they should be converted to float (as whenever i try to print the values, it somehow ignores the 100000 or 1000000). raw_data = 'EISTest16_10CV_01.txt' # name of your…
sex92toso
  • 25
  • 4
1
vote
1 answer

Why doesn't my "formula" variable update automatically, like in a spreadsheet? How can I re-compute the value?

I have noticed that it's common for beginners to have the following simple logical error. Since they genuinely don't understand the problem, a) their questions can't really be said to be caused by a typo (a full explanation would be useful); b) they…
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
1
vote
1 answer

In C++, how can I create an instance of zoned_time as a class member?

I'm new to C++ and am exploring the use of timezones in chrono, specifically zoned_time. I have only one issue with it: I want to use an instance of zoned_time as a member in a class, but no matter how I alter the syntax, the compiler doesn't like…
1
vote
1 answer

How to assign multiple variables on observe/reactive in R?

I'm trying to improve my code on the server side of my R Shiny App. I have 5 different variables which are: dateFrom, duration, step, length, and format that depend on an input condition. My code for defining dateFrom is as follows : dateFrom =…
user20701170
1
vote
1 answer

Global variable exists still I get "UnboundLocalError: local variable 'a' referenced before assignment"

The following python code gives an error. Why isn't it referencing the global variable a ? a = 10 def b(x): if(x == True): a = 2 return a print(b(False)) The error: Traceback (most recent call last): File "", line 8, in…
hari19
  • 95
  • 8