Page 438 - ComputerScience_Class_11
P. 438
12.2 NUMERIC
A numeric data type is used to store numbers in a program. It includes values that represent whole numbers, decimal
numbers and complex numbers and allows mathematical operations such as addition, subtraction, multiplication and
division.
The numeric data type in Python is further divided into the following types based on the form of numbers they
represent:
• Integer (int) • Floating (float) • Complex (complex)
12.2.1 Integer
An integer (int) is a numeric data type used to store whole numbers without any decimal or fractional part. It can
include positive numbers, negative numbers and zero.
Syntax of integer is as follows:
variable_name = integer_value
Program 1: To display an integer number in Python.
Program 1.py
File Edit Format Run Options Window Help
# display the integer value
print("Integer value", 4)
# Assign an integer value to a variable
x = 50
# display the integer value
print("Integer value", x)
Output
Integer value 4
Integer value 50
12.2.2 Floating
A floating (float) is a numeric data type used to store numbers that contain a decimal point or fractional part. It can
represent both positive and negative decimal values. The syntax of a floating-point value is as follows:
variable_name = decimal_value
Program 2: To display a floating number in Python.
Program 2.py
File Edit Format Run Options Window Help
# Assign a floating value to a variable
y = 4.6
# Display the floating value
print("floating value", y)
# Adding two float numbers
print(0.5 + 0.6)
436 Touchpad Computer Science (Ver. 3.0)-XI

