0
What is output of below snippet and how ?
a=str([1,2,3,4]) print (len(a))
18 Respuestas
+ 6
You can find out WHAT the output is by actually RUNNING the code. Count the number of characters in the string and you find out why it is like that.
+ 4
print(a)
Then count.
+ 1
Output is expected when you run the code.
If you get an error, LINK your complete code. Check the indentation. Check the spellings. Check for unmatched brackets.
+ 1
Quoting myself:
Count the number of characters in the string and you find out why it is like that.
+ 1
space is inbuilt here if we use 2 space then also it counts as 1
for ex
a= str([2, 3, 4])
print(len(a))
ans is 9
if
a= str([2,3,4])
print(len(a))
then also ans is 9
0
Output is not expected please explain
0
I think output is 4
0
How output is 12
0
no output is not 12 it's wrg
0
Please run the code
0
Chara are 9 only
0
sry, output is 12 because if we convert the list to string then it counts character, comma, square bracket, and space also.. it counts 12 so ans is 12
0
Where is space
0
or if we use no space then also it count 1
0
Thanks Ritu Rani you are superb
0
I lv this compliment, thanks 🙂
0
It appears that the python complier automatically adds a space after each ( , ) ;
So, there is a total of 12 characters (including the opening and closing brackets, commas, spaces, and digits).
1. [
2. 1
3. ,
4. space
5. 2
6. ,
7. space
8. 3
9. ,
10. space
11. 4
12. ]