Python Data Types
In programming languages, different data types (e.g. int, float, string etc.) are used to store different categories of data (e.g. integer, floating point numbers, string, etc). Let’s learn some of the basic data types of Python programming - integer, float and string.Python also supports many advanced data types like list, tuple, dictionary, etc. that we will discuss later.
Integers
Integer data type is used to store numbers with no decimal parts. Examples of integer data types are 5, 10, 20, 101, -100, -505 etc.To declare an integer data type in Python programming, simply write
NameOfVariable = some initial value
Example:
marks = 85
rollNo = 2019101
Floating point
More popularly known as float, which refers to numbers that have decimal parts. Examples are 12.34, 0.001, 0.050, 101.001.To declare a float variable in Python, write
NameOfVariable = some initial value
Example:
studentHeight = 5.75
studentAge = 21.5
String
String data type is used to store text. To declare a string variable, you can write any of the following syntaxNameOfvariable = ‘some initial value’ (single quotes)
or
NameOfvariable = “some initial value” (double quotes)
Example:
StudentName = ‘K Patel’
StudentAddress = “Ahmedabad, Gujarat, India”
studentAge = ’25’
In the last example, studentAge is a string type of variable as it is written in single quote. In contrast, if we write studentAge = 25 (without quotes), it becomes is an integer type variable.
Remember that it is possible to perform mathematical operations on integer and float type of variables; but not possible on string type variable.
Read more Python Handouts
* * * * *
No comments:
Post a Comment