add

Add leading zeros to variable in list – PYTHON

Add leading zeros to variable in list Question: I tried to do some experimenting with variables in lists. Some of numbers wasn’t same length as original input. For example: Original: [012, 125, 032] Result: [12, 125, 32] How can I add leading zeros to equalise to original values? I Have tried zfill and format but …

Total answers: 1

Sum of items of a class

Sum of items of a class Question: What I have to do is to create a class that counts from a giving single argument and itself make the arithmetical operation. class Counts: def __init__(self, value=0): self.value = value def newvalue(self, other): return Counts(self.value + other) But for every I make to the code I got …

Total answers: 1

How can i add an item in a list from a json file python

How can I add an item in a list from a JSON file in Python? Question: Is there any way to append a JSON file list? Here is my JSON file content: {"language": "[‘English’, ‘French’]", "bank": 50} I would like to add the string "Spanish" to the language list. How can I do it? import …

Total answers: 3

I'm trying to perform math operation (specifically addition) with the contents of integer fields on my django models

I'm trying to perform math operation (specifically addition) with the contents of integer fields on my django models Question: I’m trying to perform math operation (specifically addition) with the values of integer fields on my django models but i kept getting this warning even before running the program: "Class ‘IntegerField’ does not define ‘add‘, so …

Total answers: 3

Add Dataframe to list of dataframes

Add Dataframe to list of dataframes Question: I have the following list of Dataframes twice: Now i want to combine these lists to one list. So i want to add all the Dataframes from list two to list one. Simple example: a = pd.DataFrame([2,3,4,5]) b = pd.DataFrame([4,7,8,9,10]) c = [a,b] d = pd.DataFrame([2,3,4,5]) e = …

Total answers: 1

Add role Python Discord Bot

Add role Python Discord Bot Question: Some help if possible please. I am using the below code to achieve adding a role to a member by using the command : @addRole @user knight . But the role isnt being added. Can anyone spot my error ? @ is my prefix and knight is the name …

Total answers: 1

add more than two objects with __add__ function

add more than two objects with __add__ function Question: I have a class it can successfully add two variables of object of class a class a(): def __add__(self, other): return self.val+other.val def __init__(self,a): self.val=a aa=a(22) bb=a(11) aa+bb 33 But when I try to give it third object to add, it through error cc=a(11) aa+bb+cc Traceback …

Total answers: 3

Function of adding two lists in Python

Function of adding two lists in Python Question: whenever I run following code of adding two lists in python below mentioned error appears def add_lists(L1, L2): R = [] for i in range(0, len(L1)): R.append(L1[i]+L2[i]) return R L2 = [3, 3, 3, 3] L1 = [1, 2, 3, 4] add_lists(L1, L2) print("Resultant list of: ", …

Total answers: 3