0

nums = [1, 3, 5, 2, 4] print(len('string'))

Why the output is 6?

10th Sep 2020, 1:34 AM
Chahit Bhardwaj
Chahit Bhardwaj - avatar
6 Réponses
+ 11
you have list with 5 elements in it!.But,you printed length of the String 'string' ('string' has 6 characters so len('string') gives 6 has the output
10th Sep 2020, 1:41 AM
chaithra Gowda
chaithra Gowda - avatar
+ 3
How many letters are in string?😉
10th Sep 2020, 1:41 AM
Steven M
Steven M - avatar
+ 3
🤗🤗🤗 are you printing string or the given array.... In this case the latter is used 🌅
10th Sep 2020, 1:49 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
Try print(len(nums)) instead
10th Sep 2020, 2:16 AM
Jason Kennedy
+ 2
This is bcoz strings have a '\0' character, so it gives you 6, included \0 this.
10th Sep 2020, 4:39 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
Because it calcualating the charachters of string like s-1 t-2 r-3 i -4 n-5 g-6 so total length is 6
11th Sep 2020, 7:17 AM
Sayyam Jain
Sayyam Jain - avatar