0

I am using python2.7. I have been experimentingn with the interpreter and found out then following unusual thing, I wrote the following code and it's working:-

    def func():
        a = 5 ; 
        print a 

When I call this function it gives the required output in the interpreter, not giving any syntax error, despite using the semicolon. Here is the screenshot:-enter image description here

Why it's not giving a syntax error

Pratik Singhal
  • 5,913
  • 10
  • 50
  • 93

2 Answers2

1

Using semicolon is the way to write several statement in one line. Second is empty in your code.

weisert
  • 185
  • 5
1

First of all dont use semi-colons to end a statement in python!

but look here to see why its allowed:

Why is semicolon allowed in this python snippet?

or here:

Python: What Does a Semi Colon Do?

they are used to put multiple statements on a single line so the interpreter is just ignoring it since there is not second statement

Community
  • 1
  • 1
Serial
  • 7,627
  • 13
  • 48
  • 67