PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 9, 2022

[FIXED] Why is a semicolon working in Python and does not result in an error?

 December 09, 2022     python, syntax, syntax-error     No comments   

Issue

I am using Python 2.7.

I have been experimenting with the interpreter and found out the 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 is it not giving a syntax error?


Solution

First of all, don’t use semicolons to end a statement in Python!

But look here to see why it’s allowed: Why is semicolon allowed in this Python snippet?

Or here: What does a semicolon do?

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



Answered By - Serial
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing