Python comments and variables

Let us see about Python comments and variables which covers the below topics.

  1. Python Comments
    • Single line comment
    • 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)
  2. Variables
    • Declaring variables
    • Assign variables
    • re-assign variables
    • Nullify variables using None Keyword

Code Repo : https://git.io/JtnlX

Slides: https://git.io/Jtckd

We have the below topics covered as part of Python learning course.

  1. Python introduction in Tamil Part 1
  2. Python introduction in Tamil Part 2
  3. Writing your first python program and how to execute it?
  4. Python syntax, indentation and data types

Watch on YouTube: https://youtu.be/aRWq1UMYgXU

Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Python comments and variables.

Python Comments

Comments in Python

  1. 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).
  2. (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.

Lets see an example below,

amt1 = 20
amt2 = 5
final_amt = amt1 + amt2  # Adding amt1 and amt2.
Multi line comments using #

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 screen
def 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 comments and its types


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)

www.aryanz.co.in

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)

Variable declarations (see below).

Python variable declarations
Python Variables Declaration
https://youtu.be/aRWq1UMYgXU
Python comments and variables - Learn Python in Tamil www.aryanz.co.in
Subscribe to out channel for more videos – https://bit.ly/aryanz-youtube

Please disable your adblocker or whitelist this site! We Provide Free content and in return, all we ask is to allow serving Ads.

Pin It on Pinterest

Share This
%d bloggers like this: