Data Types
- Data types are the classification or categorization of data items.
- It represents the kind of value that tells what operations can be performed on a particular data.
- Python has some data types built-in by default
- Data type is an important concept in programming.
2. Dictionary
3. Boolean
4. Set
5. Sequence Type
Numeric Datatype
Numeric data types in Python include int for integers, float for
decimals, and complex for complex numbers. They support mathematical
operations.
1. Integers:
- Integers in Python represent whole numbers without decimal points.
Program:
#integer datatype
A=int(input("Enter whole number without decimal point:"))
print("Your int value is:", A)
A=int(input("Enter whole number without decimal point:"))
print("Your int value is:", A)
Output:
Enter whole number without decimal point:23
Your int value is:23
2. Float:
- Floats in Python are numbers with decimal points, useful for precision calculations and storing real numbers.
Program:
#integer datatype
A=Float(input("Enter number with decimal point:"))
print("Your Float value is:", A)
A=Float(input("Enter number with decimal point:"))
print("Your Float value is:", A)
Output:
Enter number with decimal point:23.12
Your Float value is:23.12
Your Float value is:23.12
3. Complex number:
- Complex numbers in Python represent numbers with real and imaginary parts.
Program:
# Input two numbers
num1 = int(input("Enter the first number:
"))
num2 = int(input("Enter the second number:
"))
# Calculate the sum
sum = num1 + num2
# Display the result
print("The sum of", num1, "and", num2, "is:", sum)
Output:
Enter the first number:20
Enter the second number:20
The sum of 20 and 10 is:30
Dictionary:
- In Python, a dictionary is an unordered set of key-value pairs.
- Every key is distinct and serves as a means of accessing the matching value.
- Using Curly braces {} and key-value pairs separated by colons are used to define dictionaries.
Program:
student = {"Name": "rosiee", "Age": 20, "English":65,"Tamil":60}
print(type(student))
print("printing student data .... ")
print(student)
Output:
<class 'dict'>
printing student data ....
{'Name': 'rosiee', 'Age': 20, 'English': 65, 'Tamil':
60}
Boolean:
- Boolean represent two values TRUE or FALSE.
- When you compare two values, the expression is evaluated and Python returns the Boolean as Answer.
Program:
print(50 > 40)
print(60 == 60)
print(10 < 5)
Output:
True
True
False
Numeric:
Set:
- Sets are used to store multiple items in a single variable.
- It is used to store List , Tuple , Dictionary.
- A set is a unordered, unchangeable datatype.
- Sets are written with curly brackets.
Program:
Gocourse = {"good", "best", "excellent"}
print(Gocourse)
Output:
{ 'best' , 'good' , 'excellent' }
Sequence Type:
-
Sequence type classes in python are, list, tuple, string.
-
There are some additional sequence type objects, these are binary
data and text string.
Strings:
-
Strings in python are surrounded by either single quotation marks, or
double quotation marks.
Program:
print("Gocourse")
print('The best')
Output:
Gocourse
The best
List:
-
Lists are used to store multiple items in a single variable.
-
Lists are created using square brackets
-
List items are ordered, changeable, and allow duplicate values.
Program:
A = ["apple", "banana", "cherry"]
print(A)
Output:
[ 'apple' , 'banana' , 'cherry']
Tuples:
-
Tuples are used to store multiple items in a single variable.
-
Tuple is a collection of ordered and unchangeable values.
-
Tuples are written with round brackets.
Program:
B = ("apple", "banana", "cherry")
print(B)
Output:
( 'apple' , 'banana' , 'cherry')