int

'int' object not iterable

旧城冷巷雨未停 提交于 2021-02-07 09:27:55
问题 i've been trying to get the sum of list that changed its values from a string to int using a function player_hand = [] def card_type(player_hand): card_value = 0 if player_hand[0] == 'A': card_value = 11 if player_hand[0] == 'J': card_value = 10 if player_hand[0] == 'Q': card_value = 10 if player_hand[0] == 'K': card_value = 10 if player_hand[0] == '2': card_value = 2 if player_hand[0] == '3': card_value = 3 if player_hand[0] == '4': card_value = 4 if player_hand[0] == '5': card_value = 5 if

Python: Test if value can be converted to an int in a list comprehension

a 夏天 提交于 2021-02-07 04:47:50
问题 Basically I want to do this; return [ row for row in listOfLists if row[x] is int ] But row[x] is a text value that may or may not be convertible to an int I'm aware that this could be done by: try: int(row[x]) except: meh But it'd be nice to do it is a one-liner. Any ideas? 回答1: If you only deal with integers, you can use str.isdigit(): Return true if all characters in the string are digits and there is at least one character, false otherwise. [row for row in listOfLists if row[x].isdigit()]

The value of the local variable is not used

你。 提交于 2021-02-05 12:36:32
问题 all of the variables above have the warning in the title. Could you please tell me why that is happening? public class DataTypes { public static void main(String[] argv) { // new feature in JDK 7 int x = 0b1010; // 12 int y = 0b1010_1010; int ssn = 444_12_7691; long phone = 408_777_6666L; double num = 9_632_401_909.1_0_3; String twoLine = "line one\nline two"; } } 回答1: The variables you declared are never used, only assigned to, therefore you're being warned. 回答2: You have defined the

The value of the local variable is not used

倖福魔咒の 提交于 2021-02-05 12:34:33
问题 all of the variables above have the warning in the title. Could you please tell me why that is happening? public class DataTypes { public static void main(String[] argv) { // new feature in JDK 7 int x = 0b1010; // 12 int y = 0b1010_1010; int ssn = 444_12_7691; long phone = 408_777_6666L; double num = 9_632_401_909.1_0_3; String twoLine = "line one\nline two"; } } 回答1: The variables you declared are never used, only assigned to, therefore you're being warned. 回答2: You have defined the

int object not callable error in python [closed]

心已入冬 提交于 2021-02-05 12:21:54
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . This following section of code gave me the error fd=((1/(sd*sqrt(6.28)))*2.718**((-1(d-average)**2))/(2*sd**2))) This is the error Traceback (most recent

Cannot convert from int to boolean?

笑着哭i 提交于 2021-02-05 10:47:05
问题 public static void main(String[] args) { int [] newArray= new int [4]; int [] array = {4,5,6,7}; oddEven(array); newArray[0] = array[0]+array[1]+array[2]+array[3]; newArray[1] = array[0]*array[1]*array[2]*array[3]; } public static void oddEven(int [] oddEven) { for (int i=0; i<oddEven.length; i++) { // Cannot convert from int to boolean if (oddEven[i] % 2) } } Ignore what I'm trying to manage here. I'm only curious why it doesn't accept "if" statement in this for loop. As I stated it says

What does long <name> = (long) <expression>; do in Java? [duplicate]

不羁的心 提交于 2021-02-05 08:08:54
问题 This question already has answers here : Casting variables in Java (5 answers) Closed 4 years ago . What do (long) and (int) in the following statements before the expression mean? long years = (long) (minutes / minutesInYear); int remainingDays = (int) (minutes / 60 / 24) % 365; 回答1: (minutes / minutesInYear) is unclear as to what variable type it will return. If you want it in an int variable, you must write (int) before it. This is called "typecasting", and it basically converts one format

What does long <name> = (long) <expression>; do in Java? [duplicate]

这一生的挚爱 提交于 2021-02-05 08:03:52
问题 This question already has answers here : Casting variables in Java (5 answers) Closed 4 years ago . What do (long) and (int) in the following statements before the expression mean? long years = (long) (minutes / minutesInYear); int remainingDays = (int) (minutes / 60 / 24) % 365; 回答1: (minutes / minutesInYear) is unclear as to what variable type it will return. If you want it in an int variable, you must write (int) before it. This is called "typecasting", and it basically converts one format

python: concatenate integer items in a list to a single string

我只是一个虾纸丫 提交于 2021-02-05 06:10:43
问题 Is there a better way of the following for concatenating items in a list that are "integers" into a string: import numpy as np my_list = [1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0] changed_list = np.char.mod('%d', my_list) final_ans = ''.join(changed_list ) 回答1: Im not sure what you mean by better, but you could try this. ''.join([str(x) for x in my_list]) 回答2: how about this? ''.join([str(item) for item in my_list]) 回答3: You can use the bitstring module: >>> from bitstring import BitArray >>> f'

Subclassing int and overriding the __init__ method - Python [duplicate]

爷,独闯天下 提交于 2021-02-05 06:00:47
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: inheritance from str or int Hi folks, I'm trying to subclass the int class without any success. Here is my attempt: class SpecialInt(int): def __init__(self, x, base=10, important_text=''): int.__init__(self, x, base) self.important_text=important_text If I perform the following: integer = SpecialInt(123, 10, 'rage of the unicorns') I get this error: TypeRror: int() takes at most 2 arguments (3 given) Any ideas?