Data type refers to the type of data that a variable stores. Data types can be broadly categorized into five different types, listed as follows:
Python has integers, long integers, floating point numbers, and complex numbers as numeric data types.
a. Integers and long integer
Integers are numbers with no decimal parts. Integers include zero, all of the positive whole numbers, and all of the negative whole numbers such as -5, -4, -3, 0, 5, 7 etc. The int or integer data type ranges from -2^31 to (2^31-1); the leading minus sign shows the negative values. Beyond these ranges, the interpreter will add L to indicate a long integer.
To declare an integer in Python, simply write variableName = initial value
Example:
emp_age = 100
emp_no = 1106
Boolean data type
Boolean data type is a sub type of integers. A Boolean data type generally has only two values 'True' or 'False'.
Syntax:
<variable name>=<'True' or 'False'>
Boolean data types can be referred to as an on and off switch, which has only two values to chose from:
As you can see we try to compare the value of x with the value of y, and when we use the == operator, the value of the Boolean is returned as True.
b. Floating point numbers
Numbers that have decimal parts, such as 1.234, -0.023, 12.01 are referred to as floating point
numbers in the programming language.
The floating point number type ranges approximately from -10 to 10^308 and has 16 digits of precision.
There are two ways to write a floating point number. It can be written using ordinary decimal notation or scientific notation. Scientific notation is often useful for mentioning very large numbers.
To declare a float in Python, we write variableName = initial value
Example:
emp_height = 1.82
emp_weight = 67.2
c. Complex numbers
A complex number has both real and imaginary parts, and Python allows you to specify
this data type in a very easy and convenient way.
Syntax:
<variable name>=complex(x,y)
OR
<variable name>=x+yj
Here, x is the real part and y is the imaginary part. Here, j plays the role of iota. See the screen shot below:
By the way this was also one of the methods to run python using the command prompt of your machine.
As you can see we declare two variables to denote complex numbers. One way to achieve is to use
complex() method and the other way is to use the standard notation as used in mathematics.
- Numbers
- String
- Tuples
- List
- Dictionary
Python has integers, long integers, floating point numbers, and complex numbers as numeric data types.
a. Integers and long integer
Integers are numbers with no decimal parts. Integers include zero, all of the positive whole numbers, and all of the negative whole numbers such as -5, -4, -3, 0, 5, 7 etc. The int or integer data type ranges from -2^31 to (2^31-1); the leading minus sign shows the negative values. Beyond these ranges, the interpreter will add L to indicate a long integer.
To declare an integer in Python, simply write variableName = initial value
Example:
emp_age = 100
emp_no = 1106
Boolean data type
Boolean data type is a sub type of integers. A Boolean data type generally has only two values 'True' or 'False'.
Syntax:
<variable name>=<'True' or 'False'>
Boolean data types can be referred to as an on and off switch, which has only two values to chose from:
As you can see we try to compare the value of x with the value of y, and when we use the == operator, the value of the Boolean is returned as True.
b. Floating point numbers
Numbers that have decimal parts, such as 1.234, -0.023, 12.01 are referred to as floating point
numbers in the programming language.
The floating point number type ranges approximately from -10 to 10^308 and has 16 digits of precision.
There are two ways to write a floating point number. It can be written using ordinary decimal notation or scientific notation. Scientific notation is often useful for mentioning very large numbers.
To declare a float in Python, we write variableName = initial value
Example:
emp_height = 1.82
emp_weight = 67.2
c. Complex numbers
A complex number has both real and imaginary parts, and Python allows you to specify
this data type in a very easy and convenient way.
Syntax:
<variable name>=complex(x,y)
OR
<variable name>=x+yj
Here, x is the real part and y is the imaginary part. Here, j plays the role of iota. See the screen shot below:
By the way this was also one of the methods to run python using the command prompt of your machine.
As you can see we declare two variables to denote complex numbers. One way to achieve is to use
complex() method and the other way is to use the standard notation as used in mathematics.
0 comments:
Post a Comment