Python Data Types-in Bengali
Python Data Types – বাংলা-ইংলিশে সহজ ব্যাখ্যা
🧠 কী শিখবেন এই টিউটোরিয়াল থেকে?
- Python Data Types এর সংজ্ঞা ও গুরুত্ব
- int, float, string ও boolean ডেটা টাইপ
- টাইপ কনভার্সন (type conversion)
- কিছু কমন ভুল ও এর সমাধান
🎯 Data Types কী?
Data types হল এমন একটা classification system যা বলে দেয় একটা ভেরিয়েবল কী ধরনের ডেটা ধরে রাখে। যেমন:
- int: পূর্ণ সংখ্যা
- float: দশমিক সংখ্যা
- str: টেক্সট
- bool: সত্য/মিথ্যা (True/False)
ডেটা টাইপ জানলে Python বুঝতে পারে, memory allocation কীভাবে হবে এবং কোন ধরনের operation করা যাবে।
🔢 Integer (int) উদাহরণ
age = 35
print(type(age)) # Output: <class 'int'>
এইখানে age ভেরিয়েবলের মধ্যে একটি integer মান রাখা হয়েছে।
🌊 Float উদাহরণ
height = 5.11
print(type(height)) # Output: <class 'float'>
ভেরিয়েবলের মধ্যে দশমিক সংখ্যা থাকলে তা float ধরণের হয়।
📝 String উদাহরণ
name = "Krish"
print(type(name)) # Output: <class 'str'>
String মানে টেক্সট – যেকোনো অক্ষর বা শব্দের সমন্বয়।
✅ Boolean উদাহরণ
is_student = True
print(type(is_student)) # Output: <class 'bool'>
Boolean type সাধারণত decision-making বা condition check করতে ব্যবহৃত হয়।
🔁 Type Conversion
age = 25
age_str = str(age)
print(type(age_str)) # Output: <class 'str'>
height = "5.9"
height_float = float(height)
print(type(height_float)) # Output: <class 'float'>
Python এ বিভিন্ন টাইপের মধ্যে রূপান্তর (conversion) খুব সহজে করা যায়।
⚠️ কমন ভুল ও সমাধান
result = "Hello"
result += 5 # Error!
উপরের কোডে string এর সাথে int যোগ করতে গিয়ে error হচ্ছে। সমাধান:
result = "Hello"
result += str(5) # Output: Hello5
📚 কুইজ: আপনার জানা যাচাই করুন
- Python এ string datatype চেনার জন্য কোন keyword ব্যবহৃত হয়?
- True এবং False কোন ডেটা টাইপের অংশ?
- float কে int এ convert করলে কী হয়?
🧪 Practice Quiz: Python Data Types
1. Which of the following is a valid float value in Python?
- 10
- 10.5
- "10"
- True
2. What will be the type of the result of this code?
type("25")
- str
- int
- bool
- float
3. What does the `bool` data type represent?
- Decimal numbers
- Text strings
- True or False values
- Whole numbers
4. What is the output of this code?int("50")
- "50"
- 50
- True
- Error
5. Which one is an invalid variable assignment?
- name = "Krish"
- age = 25
- 1name = "Wrong"
- is_student = True