Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Python Data Types Full Guide with Example

Python Data Types Full Guide with Example

Become More Then A coder | Learn & Start Coding Now.

✅ Python Data Types – Full Guide with Examples


🔹 What is a Data Type?

A data type defines the type of value a variable holds.
Python is dynamically typed, so it automatically detects the data type when you assign a value.

x = 10           # int
y = 3.14         # float
name = "Arvind"  # string

Use type() to check:

print(type(x))  # <class 'int'>

🔸 1. Numeric Types

int – Whole numbers

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

float – Decimal numbers

b = 99.99
print(type(b))      # <class 'float'>

complex – Complex numbers

c = 3 + 4j
print(type(c))      # <class 'complex'>

📌 Use Case: Finance, math, engineering.


🔸 2. Text Type

str – String (sequence of characters)

name = "Arvind"
msg = 'Hello'
print(type(name))   # <class 'str'>

✅ Strings can be:

  • Single 'Hello'
  • Double "Hello"
  • Triple '''Multi-line'''

🔸 3. Boolean Type

bool – Only two values: True or False

is_active = True
print(type(is_active))  # <class 'bool'>

📌 Used for logic, conditions, switches.


🔸 4. Sequence Types

list – Ordered, changeable, allows duplicates

fruits = ["apple", "banana", "mango"]
print(type(fruits))     # <class 'list'>
print(fruits[0])        # apple

tuple – Ordered, unchangeable, allows duplicates

colors = ("red", "blue", "green")
print(type(colors))     # <class 'tuple'>

range – Represents a range of numbers

r = range(1, 6)
print(list(r))          # [1, 2, 3, 4, 5]

🔸 5. Set Types

set – Unordered, no duplicates

nums = {1, 2, 3, 2}
print(nums)             # {1, 2, 3}

frozenset – Immutable version of set

fset = frozenset([1, 2, 3])
print(fset)

🔸 6. Mapping Type

dict – Key-value pair storage

person = {"name": "Arvind", "age": 30}
print(person["name"])   # Arvind
print(type(person))     # <class 'dict'>

📌 Great for storing structured data like user profiles, configurations.


🔸 7. Binary Types

bytes

b = b"Hello"
print(type(b))          # <class 'bytes'>

bytearray

ba = bytearray([65, 66, 67])
print(ba)               # bytearray(b'ABC')

memoryview

mv = memoryview(bytes(5))
print(mv)

📌 Useful for working with binary files, images, audio, etc.


🔸 8. NoneType

None – Represents absence of value

x = None
print(type(x))          # <class 'NoneType'>

📌 Used to initialize variables or return "nothing".


✅ Type Casting (Convert Data Types)

a = int("10")           # string to int
b = float(5)            # int to float
c = str(99)             # int to string

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

✅ Real-world Example

user = {
    "name": "Arvind",       # str
    "age": 25,              # int
    "is_verified": True,    # bool
    "skills": ["Python", "AI"],  # list
}
print(user)

✅ Summary Table

Data Type Description Example
int Integer numbers x = 10
float Decimal numbers pi = 3.14
str Text/String name = "Arvind"
bool True or False is_on = True
list Ordered, mutable [1, 2, 3]
tuple Ordered, immutable (1, 2, 3)
set Unordered, unique {1, 2, 3}
dict Key-value store {"name": "Arvind"}
NoneType Empty/Null x = None

✅ Best Practices

  • Use descriptive variable names (student_name not sn)
  • Don’t confuse = (assignment) with == (comparison)
  • Prefer lists for ordered collections, sets for uniqueness
  • Use None to declare an uninitialized value
  • Always test your types with type() for clarity



Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.