Python: (lack of) punctuation
The tutor comments on a possibly surprising characteristic of Python.
Unlike Perl or Java, Python doesn’t use semicolons at the end of statements. Furthermore, it doesn’t use braces around loops. A loop body is indicated by indentation:
for i in range(3):
print(“Hello, “)
print(“how are you?”)
print(“\n”)
print(“Cheers:)”)
yields the output
Hello,
how are you?
Hello,
how are you?
Hello,
how are you?
Cheers:)
Notice that the indented print statements are executed each pass through the loop, while the non-indented print statement is only executed once.
Python’s sparse use of punctuation might surprise programmers from other languages:)
Source:
Donaldson, Toby. Python, 3rd Edition. Peachpit Press, 2014.
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.
Leave a Reply
You must be logged in to post a comment.