Data types in python and comments

In python, we don't need to specify the type of data as other programming languages like C, C++, JAVA means in other programming languages there is mandatory to declare a variable with a data type to define which type of and how much data can be store by the variable which will be used in the program.

Variable declaration in python


as we write a statement x=100 which does not specify the type of data before initializing the variable, as we give a value to a variable, type of variable will be defined, for example in the above statement we have assign 100 to a variable x so the type of variable will be an integer.

Types of data type in python

Some of the basic data types are

  • String
  • Numeric
  • bool
  • list and much more

How to know the type of variable or data?

To calculate the type of variable type() function is used.

print(type(x)) # int

print(type(y)) #float

print(type) # string

print(a) # bool

Set data type


Python comments

There are different use of a comment in python

  • To make code more readable.
  • To prevent the execution of a line of code.

Types of comment in python

  1. Single line comment
  2. Multi-line comment

Single line comment

To be ignored a line by python or comment a line of code in python pound sign(#) can be used in front of the line like given below
# sum=first_number+second_number

Multi-line comment

To be ignored multi-line code by python pound sign(#) can use in multi-line as shown below.
# sum=first_number+second_number
# average=sum/2

Post written by: Hemant Singh
© 2020 - 2020 All rights are reserved