Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Python comments and variables.
Python Comments
Comments in Python
Documentation using comments – It helps anyone reading the code along with the comments can easily understand the code easily and how it works. (Logical and Functional explanation).
(mostly this will be used for debugging your code, if the code is not working as expected and to find the line which cause the bug).
How to comment and what are all the ways we can comment in Python?
Lets see what all ways we can comment in Python.
Single line comments
End of the line comments
Multi line comments using #(Pound or Sharp)
Multi line comments using """(3 double quotes a.k.a Multi line string)
Single line comments
It is writing in one single line and These lines are prefixed using #(Pound or Sharp).
# This is Single line comment# Sample program to print hello world.print("Hello, World")# End of my python program
End of the line comments
End of line comments, as name says it is written at end of the line along with the Python code.
Multi line comments using #, it is similar to Single line comment, but it is written on multiple lines prefixed with the #(Pound or Sharp) symbol.
Primarily used for documenting python code or explaining the block of code below,
Its written at the top of a class or function.
Lets see an example below
# Author: aryanz.co.in
# Class name: calculator
# Description: This class is used for performing add, sub, multiply and divide. each action requires two parameters.
# Add operation
# Two parameters x and y
# prints the result on the screendef add(x, y)
print(x + y)
Multi line comments using “””
It is same as Multi line comment using # but it is prefixed with the """(3 double quotes).
Similar to the Multi line using #, even here we can use this for documentation.
Lets see an example below
""" Author: aryanz.co.in
Class name: calculator
Description: This class is used for performing add, sub, multiply and divide. each action requires two parameters."""
""" Add operation
Two parameters x and y
prints the result on the screen"""def add(x, y)
print(x + y)
Python Variables
What is a variable?
Variables, a placeholder or container or a memory location to store values of any type, such as string, int, float, list and etc.,
A variable is a container for storing data/values.
Values are assigned at the beginning of the program.
It does not need to be declared with any particular type.
Type can be changed at any time, after they have been initialized at the beginning. (x = 5, after few line of code assign x = “Hello”, it is possible in Python)
Before assigning values to variables, it can be typecast to a specific type. (x = str(4))
Most importantly variables are case sensitive.(Msg = “Hello” and msg = “Hello” both are different variables)
Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Writing first program in Python and executing them using Python Interpreter
Syntax, Indentation and Best practice
Indentation is it really needed for Python?
Well to answer for it, Yes Its is very important for us to know about the indentation. because Python does not uses the curley braces ‘{‘ or ‘}’ for enclosing the statements. where as it used the indentations for it.
Key points to remember about Indentation
Giving space or tab space at beginning of a line, is called indentation.
In Python Indentation plays important role.
It uses the space to determine the block of statements.
The first line of Python code should not have indentation.(it will throw IndentationError)
Python coding best practices
Lets us see some best practices to be followed while writing Python, these best practices are followed so that your code does not end up having errors, easy to read and understand the code or the logic.
Python Indentation Rules
We can’t split indentation into multiple lines using backslash.
The first line of Python code can’t have indentation, it will throw IndentationError.
You should avoid mixing tabs and white spaces to create indentation. It’s because text editors in Non-Unix systems behave differently and mixing them can cause wrong indentation.
It is preferred to use white-spaces for indentation than the tab character.
The best practice is to use 4 white-spaces for first indentation and then keep adding additional 4 white-spaces to increase the indentation.
We will have another exclusive video coming up on the topic “Python coding best practices”.
Save the above file in any folder with the name helloworld.py
.py is the file extension used to identify the file is Python script
Python Data types
In Python we have the following in-built data types.
Category
Data types
Notes/Description
Text type
str
String type, which is enclosed with double quotes Example "Hello", "Python", "Programming"
Numeric type
int, float, complex
numbers, decimal and real numbers
Sequence/Collection type
list, tuple, range
Collections, group of items.
Mapping type
dict
dictionary type which has key and value pair combination. Example: {"virus_id":20190101, "virus_name":"COVID19", "isSpreadable":True}
Set type
set, frozenset
Similar to the list, just that it excludes any duplicates and it sorts the items using natural sorting order i.e., ascending order.
Boolean type
bool
True or False its that simple.
Binary type
bytes, bytearray, memoryview
File reading and writing we can use the bytes or bytearrays. memory view is to view the byte location in the memory.
Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Writing first program in Python and executing them using Python Interpreter
Writing your first Python code
Where to write?
You can use any Notepad or Text editor for writing your Python program. But there are May IDEs available to help us with auto fill the code snippet or help us with formatting the code and check for any syntax errors.
But today we are going to write our first code, So lets use simple notepad or text editor.
Your first Python program
# This is my first Python code
# To print Hello world in the console
print("Hello World")
Save the above file in any folder with the name helloworld.py
.py is the file extension used to identify the file is Python script
Well you have now officially a Python developer, because you have written your first python code.
How to execute the Python program?
In order to execute the python program, we need Python Interpreter which will do the magic.
What is that magic?
Its the Interpretation of simple English into 0’s and 1’s, Yes the Python Interpreter is going to read your code and convert into 0’s and 1’s so that machine can understand the instructions.
To execute the Python code,
You need to open Terminal or Command prompt in your Machine.
Type “python3 filename.py” (In our case, “python3 helloworld.py”
Hit Enter, you should see the output in the console.
Got into issue while running the program?
Goto this link https://youtu.be/Mj6HSMLvikc and comment the error message. We will have a loot at what went wrong and why the error appeared.
In today’s topic we will be seeing the Python intro in Tamil – Part 2 | பைதான் கற்றுக்கொள்ளுங்கள், before proceeding if you have missed watching our previous topic “Python intro in Tamil – part 1” see below link.
In Python intro in Tamil – Part 2, We are going to see how to Download and install Python. along with that we will see the operating system supported and system minimum requirements.
Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Python programming language introduction | பைத்தான் அறிமுகம்
கணினி, மொபைல், இயந்திரங்கள் மின்னணு சாதனங்கள், அது எந்த மனிதனின் மொழியையும் புரிந்து கொள்ளவில்லை. அது என்ன புரிந்துகொள்கிறது? இது இயந்திர மொழியைப் புரிந்து கொள்ள முடியும் (இது 0 மற்றும் 1 இன் தவிர வேறு ஒன்றும் இல்லை – binary code)
High level & Low level மொழிகள்
High level மொழிகள்- எளிய ஆங்கில வாக்கியம் இயந்திரத்திற்கு வழிமுறைகளை வழங்க பயன்படுத்தப்படுகிறது. Low level மொழிகளின் எடுத்துக்காட்டு #Java, #Python மற்றும் பல Low level 0 மற்றும் 1 கள் செயல் அல்லது வழிமுறைகளைச் செய்ய இயந்திரத்தில் ஊட்டப்படுகின்றன. (Assembly மொழி மற்றும் Machine மொழிகள்)
High level to low level or machine language “Interpreter” பயன்படுத்தப்படுகிறது. எளிய ஆங்கிலத்தை 0 மற்றும் 1 க்கு மாற்ற டெவலப்பர்கள் அல்லது புரோகிராமர்களால் இந்த interpreter எழுதினார்.
பைதான் “குடியோ வான் ரோஸம்” என்பவரால் உருவாக்கப்பட்டது மற்றும் 1991 ஆம் ஆண்டில் வெளியிடப்பட்டது. வலை வடிவமைப்பு, மென்பொருள் மேம்பாடு, கணினி ஸ்கிரிப்டிங், கணிதம் மற்றும் பல இடங்களில் பைதான் பயன்படுத்தப்படுகிறது.
Computer, mobile, machines are electronic devices, it does not understand any human’s language.
Then what does computer’s understands?
Computer’s can understand only machine language, which is nothing but 0’s and 1’s – Binary code
High level or Low level programming languages
High level – It’s simple English sentence which are used for providing instructions to the machines.
Example: #Java, #Python are some of High level programming languages.
Low level – Direct 0’s and 1’s are feed into the machine to perform the action or instructions. (Assembly language and machine languages)
Interpreter
It is used for converting the High level to Low level or machine, Interpreter’s were also written by developers or programmers, to convert the simple English sentence to 0’s and 1’s.
Gudio van Rossum has created Python and released in the year 1991. It is also used in Web designing, Software development, System scripting, Mathematics and many more places.