Datatype in python.

 


In Python, data types define the kind of value a variable can store. Python i


Python Data Types

1. Numeric Types

Used to store numbers.

a) int (Integer)

Whole numbers (positive or negative).

a = 10
b = -3

b) float (Floating point)

Decimal numbers.

x = 3.14
y = -0.99

c) complex

Numbers with real + imaginary part.

z = 2 + 3j

2. String Type

Used to store text enclosed in quotes.

name = "Meenu"

3. Boolean Type

Stores True or False values.

is_valid = True

4. Sequence Types

a) list

Ordered, changeable, allows duplicates.

fruits = ["apple", "banana", "mango"]

b) tuple

Ordered, unchangeable, allows duplicates.

data = (10, 20, 30)

c) range

Represents a sequence of numbers.

r = range(5)   # 0 to 4

5. Mapping Type

dict (Dictionary)

Stores data in key–value pairs.

student = {"name": "Meenu", "age": 21}

6. Set Types

a) set

Unordered, no duplicates.

colors = {"red", "green", "blue"}

b) frozenset

Like set, but immutable.

fs = frozenset([1, 2, 3])

7. None Type

Represents no value.

x = None

📌 Example Program

a = 10           # int
b = 3.5          # float
c = "Hello"      # string
d = True         # boolean
e = [1, 2, 3]    # list
f = (4, 5, 6)    # tuple
g = {"x": 10}    # dict
h = {1, 2, 3}    # set
i = None         # NoneTypeSure! Here is more detailed and easy-to-understand notes on Python Data Types.

Detailed Notes on Python Data Types

Python has built-in data types that classify the type of value stored in variables. These types help Python understand how to store and process the data.


🔶 1. Numeric Data Types

a) int (Integer)

  • Whole numbers (no decimals)
  • Positive or negative
  • No limit on size (Python handles big numbers)

Examples:

a = 10
b = -45
c = 1000000

b) float

  • Decimal numbers
  • Used when precision is needed

Examples:

x = 3.14
y = -0.55

c) complex

  • Includes real + imaginary parts
  • Imaginary part is written using j

Example:

z = 2 + 3j

🔶 2. String (str)

  • Collection of characters
  • Written in single ' ', double " ", or triple quotes ''' '''

Example:

name = "Meenu"

String characteristics:

  • Ordered
  • Immutable (cannot change characters directly)

🔶 3. Boolean (bool)

Used for logical values.

Values:

  • True
  • False

Example:

is_ready = True

🔶 4. Sequence Types

a) list

  • Ordered
  • Changeable (mutable)
  • Allows duplicates

Example:

fruits = ["apple", "banana", "grapes"]

b) tuple

  • Ordered
  • Not changeable (immutable)
  • Allows duplicates

Example:

numbers = (10, 20, 30)

c) range

Used to generate a sequence of numbers.

Example:

r = range(1, 6)   # 1 to 5

🔶 5. Dictionary (dict)

  • Stores data in key–value pairs
  • Ordered (Python 3.7+)
  • Mutable

Example:

student = {"name": "Meenu", "age": 21}

🔶 6. Set Types

a) set

  • Unordered
  • No duplicates

Example:

colors = {"red", "green", "blue"}

b) frozenset

  • Same as set but immutable

Example:

fs = frozenset([1, 2, 3])

🔶 7. None Type

Represents the absence of value.

Example:

x = None

📌 Bonus: How to Check Data Type?

Use type() function:

a = 10
print(type(a))   # <class 'int'>



If you want, I can also give you a table, short notes, or examples with memory diagrams.

Post a Comment

0 Comments