
Example:
integer_no = 0101
print(integer_no)
Error:
SyntaxError: leading zeros in decimal integer literals are not permitted;
use an 0o prefix for octal integers
Reason for leading zero SyntaxError
In Python Programming, leading zeroes to a number value is not allowed, as having a leading zero, the number (assumed to be decimal - base 10) is considered to be an Oactal number (to the base 8)
But even to represent a number of octal (base 8( type, you have to add prefix 0o (Numeric 0 followed by lowercase letter o)
Solution/Fix
There could be one of these solutions based on what you are trying to achieve.
1. If the number is a decimal number
Example:
decimal_no = 101
2. If the number is an octal number
Example:
octal_no = 0o101
3. If the value is to be a String
Example:
string = "0101"
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- Jupyter: Safari Cant Connect to the Server localhost:8888/tree - Python
- What version of windows do I have? - Microsoft
- Simple Crossword Puzzle example using Pure HTML, CSS and JavaScript - Html
- How to install AWS Toolkit for Visual Studio Code - AWS
- Emulator: Warning: restoring GLES1 context from snapshot. App may need reloading. - Android-Studio
- How to comment code in Python - Python
- Where are Notepad++ macros stored? - NotepadPlusPlus
- How to display Line Number in Eclipse IDE - Eclipse