Monday 1 September 2014

Unnecessary semicolon :: Pylint :: W0301


Error:

Unnecessary semicolon

Description

Raised by Pylint, when an  statement ends with semicolon. semicolon is not required in python to end statement. This error is not fatal but considered a bad practice.

Example(s)

Given sample of code describe basic divide function, it takes two arguments a and b. We have simple divided first argument with second and returned result. We have putted semicolon to end simple division syntax, which is a C or perl style to end statement. Although their existence does not create problem and will execute smoothly.

    def divide(a, b):
        """
        function to take two arguments to divide first by second
        """
        try:
            result = a/b;
        except ZeroDivisionError:
            result = 0
        return result

Solution(s)

Semicolons are not needed in Python unless using multiple statements in single line, This idea is too considered poor practice. This style is used in old languages like c or perl, where semicolons are always required after each statement.

Remove Semicolon
Remove semicolon from then end of line, in-case of multiple statements Use more specific exceptions like  ZeroDivisionError, TypeError.

    def divide(a, b):
        """
        function to take two arguments to divide first by second
        """
        try:
            result = a/b
        except ZeroDivisionError:
            result = 0
        return result


2 comments:

  1. Emperor Casino Online Casino - Live Casino | Shootercasino
    Try Playamo Casino, live casino, live casino, best real money slots, live dealer games, free 제왕 카지노 코드 casino games, slot games, jackpots and more.

    ReplyDelete
  2. Evolution Gaming Casinos 2021
    Evolution Gaming is back in full force in the online 슬롯 사이트 casino world. They have introduced 룰렛 Live 먹튀 신고 Casino 188bet and Roulette. 미스터플레이 To be successful, you can

    ReplyDelete