Python Programming

Department of Computing, Imperial College London

home

Python for Java Programmers

  • Chapter 1: Introduction
    • [1.1] Introduction
    • [1.2] The Zen of Python
    • [1.3] Example Python program
    • [1.4] Python vs. Java - Main method
    • [1.5] Python vs. Java - Variable declaration
    • [1.6] Python vs. Java - Semicolons
    • [1.7] Python vs. Java - Braces
    • [1.8] Python vs. Java - Comments
    • [1.9] Running Python
    • [1.10] Running Python as a script
    • [1.11] Running Python interactively
  • Chapter 2: Basic data types
  • Chapter 3: Variables and operators
  • Chapter 4: Sequence types
  • Chapter 5: Sets and dictionaries
  • Chapter 6: Control flow
  • Chapter 7: Functions
  • Chapter 8: Object-oriented programming
  • Chapter 9: Modules
  • Chapter 10: Files

Chapter 1: Introduction

Python vs. Java - Comments

face Josiah Wang

In Python, single-line comments are marked with a #.

Simple guessing game - Java vs Python (comments)

If you need multiline comments, you can use triple quotes """ or ''' to mark the start and the end of comments.

"""
This is a program 
that prints 0, 1, and 2
"""

# Single line comment
i = 0   # Just like in Java
while i < 3:
   '''
   Three single quotes
   also works
   '''
   print(i)
   i += 1
Previous Next

Page designed by Josiah Wang

Department of Computing | Imperial College London