For the first Output = [3, 8, 7, 9]
I had given manual input and for the second Output = ['3', '8', '7', '9']
I had asked for an input list. So, now I am wondering both being the lists what could be the diff?

- 53
- 5
-
2One list contains int elements. The other contains string elements. I assume this is because you created a for loop asking for string inputs. Yes you entered integers but python changed them to string. ```(input("Enter a number"))``` I assume – Buddy Bob Apr 04 '21 at 03:20
-
Fair enough, understood.. thanks! :) – Marshall Apr 04 '21 at 03:24
-
Might be useful: [How can I read inputs as numbers?](https://stackoverflow.com/q/20449427/2745495) – Gino Mempin Apr 04 '21 at 03:34
-
Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [ask] from the [tour]. "Teach me this basic language feature" is off-topic for Stack Overflow. You have to make an honest attempt at the solution, and then ask a _specific_ question about your implementation. Stack Overflow is not intended to replace existing tutorials and documentation. – TigerhawkT3 Apr 04 '21 at 04:27
2 Answers
One list contains integer (int
) values, while the other contains string (str
) values. An integer value can be used in mathematical equations and mathematical comparisons (for instance, if x > 0
), while string values are usually used to display words or text, and cannot be used in equations. For instance, if you had
string_var = "1"
int_var = 1
print(int_var * 2)
print(string_var * 2)
The string variable (in quotes) cannot be multiplied (it instead returns 11
, which obviously isn't correct. The integer variable is multiplied successfully. Strings are better used when saving words or non-number values into a variable. You can research more on strings and integers online.

- 454
- 2
- 11
as BuddyBobIII said, all of the first list elements are int
s which refers to Integer
s as whole numbers, but the second one are string
s which refers to text elements and cannot use in mathematical operations.
if you want to change the second to integers, you can use map
function to change all elements of an iterable variable to integers:
a = ['1','2', '3' , '4']
print(list(map(int, a)))
Output:
[1, 2, 3, 4]

- 3,464
- 1
- 8
- 29