Why am I not required to have a semicolon at the end of anything so far?


#1

In the lessons so far we have not been told to use semicolons nor has the editor given me error about it. In all of the other languages I have learned they required a semicolon at the end of a statement. Why is this not the case when writing in Python?


#2

StackOverflow.com is a good site to find information about coding. Here is a explanation of Python and semicolons:


#3

The reason for this is because python is about ease of use so all that extra stuff like in C#, C, C++ JavaScript is not needed because they syntax does not require it.

It makes getting the code from idea to implementation so much quicker that a lot of times you can go from idea to working project before someone in C can even get a prototype working.

The there are only a few things that reuire a direct hey this here has ended statement which in python is the : and you use it at the end of loop statements and if/else statements, also try is another one off the top of my head that requires it.

EXAMPLE:

for x in range(5):
    print(x)
if 1 ==1:
    print(True)
while True:
    return False
try:
    int(raw_input("Enter a number")
except ValueError as error:
    print(error, ValueError)
finally:
    print("Finished")

All the above are examples of where you need to explicitly tell the syntax hey this statement is over. Most of the other times it is over when the word is done being used.


#4

Unlike other languages like Java, JavaScript, PHP etc python does not require a semicolon to terminate statement but
rather you can be used as a delimiter when you wish to write multiple statements on one line

print "semicolon after"; x = "delimeter";
print x;

#5

@albionsrefuge @rydan

I always forget about the semicolon funness, it is generally bad form in python to use it. While you can use it it just is not good form at all.


#6

@zeziba Yeah sometimes when i do some work in Java and I return to python i mistakenly put semicolons when I am not supposed to. Haahah!! :grin: