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

x=100

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.

x=100
print(type(x)) # int

y=12.5
print(type(y)) #float

z="USA"
print(type) # string

a=True
print(a) # bool

Set data type

x=int(100)
y=float(200)
z=str("America")

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