Followers

Latest techys

Part8- Python Fundamentals | Start from the basics

 

If u fell any difficulty in watching the content, try to reduce the size of this page or rotate your portable device if you are using it



In the previous article, we learnt about Barebones of Python program. Today we shall learn about Python Styles and Conventions. So let's go.


While working in Python, it is necessary to keep in mind certain rules & conventions.

Some very basic and elementary style rules of Python are as follows:

    1. Statement Termination: There is no symbol to terminate(end) a statement. A code-line gets terminated by default when you press the Enter key after completing your one line syntax.


    2. Maximum Line Length: The maximum line length i.e. number of characters in a line of a Python program is 79.

    3. Lines and Indentation: Blocks of code are denoted by line indentation, which is enforced through four spaces(not tabs) per indentation level.



    4. Blank Lines: We should use (a) two blank lines between top-level definitions, (b) one blank line between function/method definitions, (c) function/method definitions should be separated with two blank lines and (d) Class definitions with three blank lines.



    5. Multiple Statements in one line: You must avoid multiple statements in a single line although you can do that by using a semicolon(;) symbol between two statements but it is not recommended because it makes the syntax untidy.



    6. Whitespace: You should always have whitespace around operators and after every punctuation mark except parentheses. 

    Python considers 6 characters as whitespace. They are: 

a) ' ' (space)        b) '\n' (newline)        c) '\t' (horizontal tab)        d) '\v' (vertical tab)       

 e)'\f' (formfeed)        f) '\r' (carriage return)

    7. Case Sensitive: Python is case sensitive, so you must always be careful while typing code and identifier names or it will give an error.


Output:


    8. Identifier naming: Identifier name should always start with an alphabet and not a number. It should not contain a symbol except underscore(_)



    9. Docstring Convention: By convention, we use triple quotes('''abc''') for docstrings.


In the next article, we shall learn about other components of a Python program.

No comments