By admin , 9 January, 2022

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

1. Indentation:

The recommendation is to use 4 spaces for indentation.


Blank Lines


In Python scripts, top-level function and classes are separated by two blank lines. 
Method definitions inside classes should be separated by one blank line.

Whitespaces

  • should try to avoid whitespaces in Expressions and Statements.
  • Add blank line before a single line comment
  • Break up sections of code with white space.

Imports

 each import should be on a single line.

 

Source File Encoding

 Python 3 has UTF-8 ,the default source encoding. 

 

2. naming conventions

Variables naming conventions

Use snake_case And All Lower Case

snake case: when words are separated by underscores.

Example: lower_case_with_underscores.

 

Classes naming conventions

use CamelCase for class definitions.


CamelCase: first letter capitalized With Every word.

Example: CapitalizedWords.

 

3.General conventions

  • Capitalize the first letter of a sentence.
  • Capitalize the first letter of someone’s name.
  • Add a space after the end of a sentence.
  • Add a space after each word.

4. use of comments

5. line lengths

6. use of white space

By admin , 8 January, 2022

 Function definition

syntax for defining a function is depends on the programming language because it vary from language to language

python here
...
...
   return-value-type function-name( parameter-list )
   {
        declaration of local variables;
        statements;

        return return-value;
   }

function header

The body of the function

By admin , 8 January, 2022

() : round brackets(in British English) and  'parentheses' in (American English)
{} : curly brackets(in British English) and 'braces' in (American English)
[] : square brackets(in British English) and  'brackets' in (American English)
<> : angle brackets(in British English) and 'chevrons' in (American English)  

Note : its up to you which language you would like to speak and pronounce. As I am an Indian so I would like to speak British style as our education system prefer this.

Usage:

Round brackets(Parentheses) are always used in pairs ().

Curly brackets(Braces) are used to group statements and declarations.

Square brackets(Brackets) are used primarily for array indexing. But they are also used to denote general tuples, sets and other structures depending on the language. just as in mathematics. There may be several other uses as well.

By admin , 6 January, 2022

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Indentation

Indentation is an empty space (whitespace) used at the beginning of any statement to start new paragraph.

 indentation should be consistent throughout your code.

Indents
There are two types of indents:


Horizontal indents: spaces at the left 2 or 4 spaces.


Vertical indents(hanging indent): empty lines for splitting code into logical blocks.

Indentation in Python is mandatory.

Indentation in other languages like C,C++,Java etc is just for readability but in python, the indentation is a mandatory concept that should be followed when writing a python code, otherwise, python interpreter will  thrown IndentationError.

 

Reason why indentation is important in python

because the indentation serves another purpose other than code readability 

  • To represent a block of code(Python treats the statements as a single block of code that  have the same indentation level.)
  •  Without indentation, Python interpreter will get confused and does not know which statement to execute next or which statement belongs to which block.
  • Indentation helps interpreter to understand the order in which each block/statement should be executed.

Python Indentation Rules

  • The first line of Python code can’t have indentation, it will throw IndentationError.
  • The best practice is to use 4 spaces for indentation.
  • If you have multiple lines inside the if block, all the lines will need to be indented with same level otherwise You will get indentation error
  • If there is colon at the end of a line, you will need to indent the next line/lines by ignoring your current level of indentation.
  • If there is no colon, you should not indent the starting of a line.
  • Python doesn't allow mixing tabs and spaces for indentation.

 

4-space or 2-space indentation

 

Indentation style

There are several styles .Pick a style that suits you, then use it consistently.

  1. Allman
  2. K&R(Kernighan & Ritchie Style)
  3. GNU
  4. Whitesmiths
  5. Horstmann
  6. Haskell
  7. Pico
  8. Ratliff
  9. Lisp

K&R(Kernighan & Ritchie Style) In K&R, single-line blocks do not have braces.

By admin , 5 January, 2022

Centralized version control systems

SVN is a Centralized version control systems used for manage and keep track of your source code history.

Centralized version control systems Example :SVN 

 

Distributed  version control system

Git is a Distributed  version control system used for manage and keep track of your source code history.

Distributed version control systems Example :Git