0

Why the output of this code is 5

S = 'A\nB\tC' Print(len(s))

11th Feb 2019, 6:58 AM
H.code
2 Answers
+ 2
You have 5 characters in your string, and hence a length of 5. Character 'A', '\n' (newline), 'B', '\t' (horizontal tab), 'C'.
11th Feb 2019, 7:37 AM
Hatsy Rei
Hatsy Rei - avatar
0
No idea about python. 😬 I think you are trying to find the length of a string. In C language string must be in double quotes " ", so S = "ABC" while initialising the variable we don't use escape sequence. Your code will be like this in C Language. char S = "ABC"; Printf("%d", strlen(S)); return 0; Output : 3 Edit: - you are getting correct output. whatever you will write within the double quotes it will be a character that's why you are getting 5 as a output.
11th Feb 2019, 7:12 AM
Ms DhONi
Ms DhONi - avatar