.py Tech Series — Day 3— Python Basics_1.

Team Devs
3 min readApr 28, 2021

Welcome Back!. I hope you got the good introduction about Python and Installation process / online editors. Today we are going to Cover the basics of Python. I am using Google Collab for this and will be sharing the Notebook with you all via GitHub Link.

To print the output we use print function — ex: print(‘Hello World!). prints the Hello World! in output console.

Topic 1: Keywords and Identifiers:

Keywords are the resereved words used by any programming language. Keywords are ultra case sensitive.Keywords cannot be used as Identifiers, class names, Variable names etc. They have designed for some dedicated purpose and have a special meaning. we have 35 keywords in python
Example:
1. for : This helps to iterate from one value to another.
2. if: This helps for branching the logic
3. break: break the loop when some condition matches.
4.import: To import external / pre loaded packages into our program. (works like #include<stdio.h> in C.

Identifiers are the NAME given to entities like class, variables, functions in the code.
Rules for writing identifiers:
1. Keywords cannot be used as identifiers. Better to avoid combining keyword with Alpha numeric charecters and use as identifiers — ex: True_12.
2.Identifiers cannot start with Numbers. ex: 1_abc is not allowed.
3.Identifiers name must start with A-Z or a-z (Alphabets) and Underscore(_) ex: Abc_12, abc_12, _work etc
4. We can combine the Alphabets with numbers and underscore but name must not start with a number. ex: Work_12_2, _Work_12_2 is valid but 12_2_work is not valid
5. No Special Charecter like !,@,$,% any where is identifer are not allowed to use in Identifier. Only is allowed.

Comments:

In any progamming language, we use comments to explain about the code snippit or process we are working. Its always a good practice to give comments during the Development. Comments make code more readable
Thumb Rule: Comments will not be interpreted by Interpreted or compiled by a compiler.

Single Line Comment: we use ‘#’ in Python.
Example:
#print function to print the contents inside into the output console.
print(‘Hello World’)

Multi Line Comment: we use triple ‘‘‘ comment’’’ or”””in Python.

Indentation:
Python is highly dependent on Identation, in traditional language we use {} to represent some block of code but Python has dedicated rules for Indentation, Missing those rules Interpreter will throw indentation errors. In Python a Block of code start with Indentation and ends with First non Identated line. its developers call to decide how much Indent we have to in the program. Generally 4 Whitespaces are used in Industry. Python will throw IndentationError when there is an error in indenting.

Better not to use Tab for Indentation because different editors take Tab differently

Statements:
Statement are instructions that python interpereter executes.

  1. A = 1#Assigning value ‘1’ into a Variable ‘A’.
  2. Mutli line Statement needed “\” at end of each statement or pack all line in single brackets ()
  3. Mutliple assignement also possible — a,b,c = 10,20,30 — now a hold 10 , b holds 20 , c holds 30
  4. Multiple statements in single line — seperated via ‘;’ A=10;B=20;C=30;

All the Contents explained above are written clearly in below Collab document via Google Drive link. Refer the below document for coding level Understanding.

https://colab.research.google.com/drive/1D_oR1lgYA7L3gkMY_3vhFjBhWjqKpmbL?usp=sharing

We will start variables, Data types, Branching in upcoming sessions.

Written by: Sai Murali Pavan Rayavarapu from Team Devs.

--

--