Error in list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Error in list

This creates an error -------------------------------------- names=["Mumma : ", "Pappa : ", "Khand : ", "Rajan : ", "Manu : "] contacts=[72167, 00475, 78842, 43142, 71390] for i in range(5): print(names[i],end="") print(contacts[i]) ------------------------------------------- But when 00475 is replaced with 20475 Or anything starting for some other numeric not 0, that doesn't creates an error For example ---------------------- names=["Mumma : ", "Pappa : ", "Khand : ", "Rajan : ", "Manu : "] contacts=[72167, 20475, 78842, 43142, 71390] for i in range(5): print(names[i],end="") print(contacts[i]) ------------------------------------------ Doesn't create an error

14th Mar 2019, 4:58 AM
Manpreet Kaur
Manpreet Kaur - avatar
4 Answers
+ 6
In Python, numbers which start with 0 are octal. https://stackoverflow.com/questions/11620151/what-do-numbers-starting-with-0-mean-in-python If you want to store contact numbers, store them as strings instead of numeric literals.
14th Mar 2019, 5:07 AM
Fermi
Fermi - avatar
+ 6
In Python 3.x, a leading zero signifies that the number is not decimal and that a letter is expected. 0b begins a binary number, 0o begins an octal number and 0x begins a hexadecimal number. Try using 0o475 and see what you get. See http://www.java2s.com/Tutorials/Python/Data_Types/How_to_create_integer_in_Python_octal_binary_hexadecimal_and_long_integer.htm By the way, when you do a "for i in range(5):" kind of loop, you don't need to increment i as well - that's overkill. Delete or comment out the increment line and you will see the code runs just the same :)
14th Mar 2019, 5:25 AM
David Ashton
David Ashton - avatar
+ 2
Hmmm thnxx
14th Mar 2019, 5:27 AM
Manpreet Kaur
Manpreet Kaur - avatar
+ 1
Can you please elaborate this,"In Python, numbers which start with 0 are octal. "
14th Mar 2019, 5:11 AM
Manpreet Kaur
Manpreet Kaur - avatar