Skip to main content

All Questions

0 votes
1 answer
131 views

Variable assignment in an f-string [duplicate]

Question question regarding f-strings and expressions in Python 3. The Python documentation states clearly that: Formatted string literals (also called f-strings for short) let you include the value ...
the_slug's user avatar
  • 117
0 votes
0 answers
42 views

How does assignment to another assignment(adding an element in a dictionary) work? [duplicate]

Let's imagine a dictionary and we want to get some kind of a "reference" to a value that hasn't been populated yet. >>> d = {} # This dictionary may have a huge number of elements. &...
starriet 차주녕's user avatar
0 votes
1 answer
21 views

Does performing operations on an empty linked list Node assigned to another node cause change in the original node in python3?

As mentioned here, if I have two variables x & y x = 0 y = x y += 1 print (x) #prints 0 Here the code will print 0, since assigning x to y and then changing y does not change x. However, in the ...
Ayush's user avatar
  • 49
0 votes
1 answer
27 views

UnboundLocalError: Python

I am trying to write a functions for ETS forecast. Here is my code: # evaluate an ETS model for a given parameters (t,d,s,p,b,r) def train_ets_model(train, test, cfg): t,d,s,p,b,r = cfg # ...
Mridul Bhardwaj's user avatar
0 votes
1 answer
43 views

one function used to change variable in another function

I am trying to teach myself python, so I have made a project a few smaller projects working together and one of them is a Date tracker. The Date function works. However, when I try to call the new day ...
Rulian's user avatar
  • 1
0 votes
1 answer
181 views

How to validate list items and give an error message when false?

So I'm making a game for my class. It's text based and uses a variety of rooms and items in order to complete the game. I've figured out a way to move in between rooms and to acquire the items. I have ...
Caleb Simpson's user avatar
0 votes
1 answer
49 views

Multiple changes to the same variable within different if statements

SOLVED: I read through my code, it was a 'bug'. When I copied the dice roll method from the 'player character', since it uses the same mechanics for the enemies, I set the damage to 0 if it rolls with ...
Tankerka's user avatar
0 votes
1 answer
29 views

Is there a difference between assigning several variables in one line and doing it one by one in Python?

I am a complete beginner when it comes to Python and recently I tried to reverse a linked list on Leetcode.I wrote some code, tested it and got a wrong answer. Here is my code: class Solution: def ...
George's user avatar
  • 123
0 votes
1 answer
58 views

trying to perform a calculation using values from a list with conditional output (also a list) values and keep getting item assignment error

I am trying to get an output list by using conditions to determine the values. For some conditions I want to set the output to a constant and for other conditions I want to perform a calculation from ...
zaphod_f's user avatar
1 vote
2 answers
427 views

How To Store Column Mean As a Variable

ISSUE I am performing data cleansing. I have calculated a column mean based on conditions fed into the .loc() function. Storing this output in the z variable is producing a (1,1) dataframe and ...
P-Sides's user avatar
  • 79
1 vote
1 answer
43 views

Assign "variable variables" to a directory

I would like to assign the following variable names to a directory for easy manipulation later. The idea is as follow: data_1= fits.getdata(.....) data_2= fits.getdata(.....) data_3= fits.getdata(........
Jeicot Delgado's user avatar
-1 votes
1 answer
146 views

Double assignment of same variable in one expression in Python - does it have any purpose?

I was going through the delta lake documentation page. There is a line like this : from delta import * builder = pyspark.sql.SparkSession.builder.appName("MyApp") \ .config("spark....
Sairam Krish's user avatar
  • 11.8k
0 votes
1 answer
4k views

Python Tuple Index Out of Range error after assignment to list

I jumped into some Python courses a little while ago and have gotten to a milestone project to make a simple tic-tac-toe game. But I am running into a bit of a wall due to an index error that keeps ...
deceparis's user avatar
2 votes
4 answers
578 views

How to pass **kwargs parameters to the relevant wrapped functions?

I want to define a wrapper function that wraps up a number of other functions with many arguments and want to use the magic variables in the wrapper function. For example, suppose I have these three ...
msh855's user avatar
  • 1,571
0 votes
1 answer
124 views

Assign list without reference [duplicate]

Let's see an example, list1 = ["a", "b", "c"] list2 = list1 then I append in list1 list1.append(1) list1.append(2) list1.append(3) then list1 will look like list1 = [&...
Rezaul Karim Shaon's user avatar

15 30 50 per page
1
2 3 4 5
8