Python DataType

                                        python datatype 

In Python, data types define the kind of value a variable store, such as numbers, text, or collections.

1. Numeric Data Types

a = 10          # int (Integer)
b = 10.5        # float (Decimal)
c = 3 + 4j      # complex (Complex number)

Example:

print(type(a))
print(type(b))
print(type(c))

Output:
<class 'int'>
<class 'float'>
<class 'complex'>

2. String (str)

A string is a sequence of characters.

name = "Ram"

city = 'Mumbai'


print(name)

print(type(name))


Output:-

Ram

<class 'str'>


3. Boolean (bool)

Stores either True or False.


is_student = True

is_working = False



4. List (list)

An ordered, mutable collection. You can add, remove, or change items.


fruits = ["Apple", "Banana", "Mango"]

fruits.append("Orange")

print(fruits)



5. Tuple (tuple)

An ordered, immutable collection. Once created, it cannot be changed.


colors = ("Red", "Green", "Blue")

6. Set (set)

An unordered collection of unique items.


numbers = {1, 2, 3, 4}


7. Dictionary (dict)

Stores data as key-value pairs.


student = {

    "name": "Ram",

    "age": 25,

    "city": "Mumbai"

}


Recommended learning order

Since you're starting Python for data analytics, learn the data types in this order:

  1. int
  2. float
  3. str
  4. bool
  5. list ⭐ (most important for NumPy and Pandas)
  6. tuple
  7. set
  8. dict ⭐ (very important)
  9. None

Comments

Popular posts from this blog

Two Sum II - Input Array Is Sorted

Comparable Vs. Comparator in Java

First negative in every window of size k