
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to put comments inside a Python dictionary?
You can put comments like you normally would anywhere in a python script. But note that you can only put single line comments using #. Multiline comments act like strings and you cannot put just a string in between definition of a dict. For example, the following declaration is perfectly valid:
testItems = { 'TestOne': 'Hello', # 'TestTwo': None, }
But the following is not:
testItems = { 'TestOne': 'Hello', """ Some random multiline comment """ }
- Related Articles
- How to put multi-line comments inside a Python dict()?
- How can we put comments in a column of existing MySQL table?
- How to define a Python dictionary within dictionary?
- Where to put comments in an if...elif..else construct?
- Are HTML comments inside script tags a best practice?
- How can I put a Java arrays inside an array?
- How to convert Javascript dictionary to Python dictionary?
- CSS to put icon inside an input element in a form
- How to convert a String representation of a Dictionary to a dictionary in Python?
- How to sort a nested Python dictionary?
- How to update a Python dictionary values?
- How to create a dictionary in Python?
- How to sort a dictionary in Python?
- How to convert Python Dictionary to a list?
- How to convert a spreadsheet to Python dictionary?

Advertisements