2

Hey been learning python3 for a while.

Came across dictionaries and the dictionary_name.get() method and tried to get a random key value.

The problem:

data= {}

data.get('key',1)

it works and returns 1

But instead if I use data.get('key',01) it says invalid token why is that?

John La Rooy
  • 295,403
  • 53
  • 369
  • 502
Leero
  • 57
  • 2
  • 8

1 Answers1

5

In Python 2.x, integer literals starting with 0 were interpreted as octal numbers. In Python 3.x, octal numbers are written with the prefix 0o instead. To avoid that old code changes meaning without any warning, literals starting with just 0 are a syntax error now.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841