Python একদম কখনো দেখোনি? কোনো সমস্যা নেই। এই গাইডটি তোমাকে একদম শুরু থেকে হাত ধরে নিয়ে যাবে — Variables থেকে শুরু করে Object Oriented Programming পর্যন্ত। Never seen Python before? No problem. This guide will take you from the very beginning — from Variables all the way to Object Oriented Programming.
Python একটি High-Level Programming Language। এটি তৈরি করেছেন Guido van Rossum, ১৯৯১ সালে। Python-এর সবচেয়ে বড় বৈশিষ্ট্য হলো এর কোড পড়তে অনেকটা ইংরেজির মতো — তাই beginner-দের জন্য এটি সবচেয়ে ভালো।Python is a High-Level Programming Language created by Guido van Rossum in 1991. Its biggest feature is that its code reads almost like English — making it the best choice for beginners.
python.org ওয়েবসাইটে যাও → Downloads → তোমার OS অনুযায়ী ডাউনলোড করো (Windows/Mac/Linux)Go to python.org → Downloads → Download for your OS (Windows/Mac/Linux)
Terminal/CMD খুলে টাইপ করো:Open Terminal/CMD and type:
VS Code ডাউনলোড করো (code.visualstudio.com) — এটাই সবচেয়ে ভালো editor। Python extension ইনস্টল করো।Download VS Code (code.visualstudio.com) — the best editor. Install the Python extension.
VS Code খুলো। একটা নতুন ফাইল তৈরি করো নাম দাও hello.py। এবার নিচের কোডটা লেখো:Open VS Code. Create a new file named hello.py. Now type the code below:
Terminal-এ গিয়ে রান করো:Run it from the terminal:
python filename.py দিয়ে প্রোগ্রাম রান করোRun programs with python filename.pyprint() হলো Python-এর সবচেয়ে বেশি ব্যবহৃত function। এটি যা দাও তাই স্ক্রিনে দেখায়।print() is Python's most used function. It displays whatever you give it on the screen.
input() দিয়ে প্রোগ্রাম চলার সময় ব্যবহারকারীর কাছ থেকে তথ্য নেওয়া যায়। মনে রেখো: input() সব কিছু string হিসেবে নেয়।input() lets you take information from the user while the program runs. Remember: input() takes everything as a string.
input() সবসময় string return করে। গণনার জন্য int() বা float() দিয়ে convert করতে হবে।
input() always returns a string. For calculations you must convert with int() or float().
Comments হলো কোডের মধ্যে মানুষের পড়ার জন্য লেখা নোট। Python এগুলো execute করে না।Comments are notes written in code for humans to read. Python doesn't execute them.
print() — স্ক্রিনে দেখায়, sep ও end দিয়ে customize করা যায়shows on screen, customizable with sep and endinput() — সবসময় string দেয়, সংখ্যার জন্য int()/float() লাগেalways gives string, need int()/float() for numbers# — single line comment, """ """ — multi-linesingle line comment, """ """ — multi-lineVariable হলো একটি নামযুক্ত বাক্স যেখানে তুমি ডেটা রাখো। যেমন একটা বাক্সে জিনিস রাখলে বাক্সের নাম ধরে সেটা খোঁজা যায়।A variable is a named box where you store data. Like putting things in a labeled box and finding them by name.
naam = "Rahim" ← "naam" নামের বাক্সে "Rahim" রাখলাম boyos = 20 ← "boyos" নামের বাক্সে 20 রাখলাম GPA = 4.75 ← "GPA" বাক্সে 4.75 রাখলাম
| Data Type | বাংলায়Description | উদাহরণExample | ব্যবহারUse |
|---|---|---|---|
int | পূর্ণ সংখ্যাWhole number | 20, -5, 1000 | বয়স, সংখ্যা গোনাAge, counting |
float | দশমিক সংখ্যাDecimal number | 3.14, -2.5 | ওজন, তাপমাত্রাWeight, temperature |
str | লেখা/পাঠ্যText | "Rahim", 'Hello' | নাম, বার্তাNames, messages |
bool | সত্য বা মিথ্যাTrue or False | True, False | শর্ত পরীক্ষাCondition checking |
list | পরিবর্তনযোগ্য তালিকাMutable list | [1, 2, 3] | একাধিক আইটেমMultiple items |
dict | key-value জোড়াKey-value pairs | {"naam": "Rahim"} | ডেটা mappingData mapping |
NoneType | কিছু নেই / খালিNothing / empty | None | শূন্য মানNull value |
type() — টাইপ জানতেto know the typeint(), float(), str() — টাইপ বদলাতেto convert types| Operator | কাজFunction | উদাহরণExample | Result |
|---|---|---|---|
+ | যোগAddition | 10 + 3 | 13 |
- | বিয়োগSubtraction | 10 - 3 | 7 |
* | গুণMultiplication | 10 * 3 | 30 |
/ | ভাগ (দশমিক)Division (decimal) | 10 / 3 | 3.333... |
// | পূর্ণ ভাগFloor division | 10 // 3 | 3 |
% | ভাগশেষ (modulo)Remainder (modulo) | 10 % 3 | 1 |
** | পাওয়ার/ঘাতPower/exponent | 2 ** 10 | 1024 |
এগুলো দুটো মান তুলনা করে এবং True বা False দেয়।These compare two values and return True or False.
| Operator | অর্থMeaning | উদাহরণExample | Result |
|---|---|---|---|
== | সমান কিনাEqual to | 5 == 5 | True |
!= | সমান নয়Not equal | 5 != 3 | True |
> | বড়Greater than | 10 > 5 | True |
< | ছোটLess than | 3 < 7 | True |
>= | বড় বা সমানGreater or equal | 5 >= 5 | True |
<= | ছোট বা সমানLess or equal | 4 <= 5 | True |
| Operator | অর্থMeaning | উদাহরণExample | Result |
|---|---|---|---|
and | দুটোই সত্য হলে TrueTrue only if both are True | True and True | True |
or | যেকোনো একটা সত্য হলে TrueTrue if at least one is True | True or False | True |
not | উল্টো করে দেয়Reverses the value | not True | False |
বাস্তব জীবনে আমরা প্রতিনিয়ত সিদ্ধান্ত নিই — "যদি বৃষ্টি হয়, তাহলে ছাতা নেব।" Python-এও একই ভাবে কাজ করে।In real life we constantly make decisions — "If it rains, I'll take an umbrella." Python works the same way.
if শর্ত: কাজ (যদি শর্ত সত্য হয়) elif অন্য শর্ত: কাজ (যদি দ্বিতীয় শর্ত সত্য) else: কাজ (যদি কোনো শর্ত না মেলে)
if — একটি শর্ত পরীক্ষাcheck one conditionelif — আরেকটি শর্ত (একাধিক হতে পারে)another condition (can have many)else — কোনো শর্ত না মিললে এটা চলেruns if no condition matchesfor loop ব্যবহার করা হয় যখন জানি কতবার কাজ করতে হবে, অথবা একটি list/sequence-এর সব item-এর উপর কাজ করতে হবে।Use for loop when you know how many times to repeat, or to work on every item in a list/sequence.
for — নির্দিষ্ট বার বা list-এর প্রতিটি item-এ কাজfixed times or each item in a listwhile — শর্ত সত্য থাকলে চলেruns while condition is Truerange(start, stop, step) — সংখ্যার ক্রম তৈরিcreates number sequencebreak — loop থামায়, stops loop, continue — এই iteration skip করেskips current iterationFunction হলো কোডের একটা নামযুক্ত block যা একটি নির্দিষ্ট কাজ করে। একবার লিখলে বারবার ব্যবহার করা যায়। রান্নার recipe-র মতো — একবার লিখলে যখন খুশি ব্যবহার করো।A function is a named block of code that does a specific job. Write once, use many times — like a cooking recipe.
def naam(): — function তৈরিcreate a functionreturn — ফলাফল ফেরত দাওreturn a result*args, **kwargs — যতো খুশি argumentas many arguments as you wantList হলো একটি ordered (ক্রমানুযায়ী) এবং changeable (পরিবর্তনযোগ্য) collection। Square brackets [ ] দিয়ে তৈরি হয়।A List is an ordered and changeable collection. Created with square brackets [ ].
Tuple, List-এর মতোই কিন্তু এটা পরিবর্তন করা যায় না। Parentheses ( ) দিয়ে তৈরি।Tuple is like a List but cannot be changed. Created with parentheses ( ).
Set-এ duplicate হয় না। Curly braces { } দিয়ে তৈরি।Sets don't have duplicates. Created with curly braces { }.
Dictionary হলো key-value pair-এর সংগ্রহ। একটা আসল Dictionary-র মতো — word (key) দিয়ে অর্থ (value) খোঁজো।A Dictionary is a collection of key-value pairs — like a real dictionary where you find meaning (value) by word (key).
| Type | ব্যবহারের সময়When to Use |
|---|---|
list | ক্রমানুযায়ী, পরিবর্তনযোগ্য তালিকাOrdered, changeable collection |
tuple | স্থির ডেটা (coordinates, settings)Fixed data (coordinates, settings) |
set | unique মান, duplicate সরাতেUnique values, removing duplicates |
dict | label দিয়ে ডেটা খোঁজাFinding data by label |
list [ ] — ordered, changeable — সবচেয়ে বেশি ব্যবহৃতordered, changeable — most usedtuple ( ) — ordered, unchangeableordered, unchangeableset { } — unordered, duplicate নেইunordered, no duplicatesdict { key: value } — key দিয়ে value খোঁজোfind value by keyf-string হলো সবচেয়ে আধুনিক এবং সহজ উপায় string-এ variable ঢোকানোর।f-string is the most modern and easy way to insert variables into strings.
f"{variable}" — সবচেয়ে সহজ string formattingeasiest string formatting| Mode | কাজFunction | ব্যাখ্যাExplanation |
|---|---|---|
"r" | পড়াRead | শুধু পড়া যাবে, ফাইল থাকতে হবেRead only, file must exist |
"w" | লেখাWrite | নতুন লেখা, আগের সব মুছে যাবেWrite new, erases existing content |
"a" | যোগ করাAppend | শেষে যোগ হবে, আগেরটা থাকবেAdds to end, keeps existing content |
"r+" | পড়া ও লেখাRead & Write | দুটোই করা যাবেBoth read and write |
with কেন ব্যবহার করবো?Why use with?with ব্যবহার করলে কাজ শেষে ফাইল automatically বন্ধ হয়ে যায়। এটা সবসময় ব্যবহার করা উচিত।
Using with automatically closes the file when done. Always use it.
open(file, mode, encoding) — ফাইল খোলাopen a file"w" — লেখা (মুছে), write (erases), "a" — যোগ করাappendread(), readlines() — ফাইল পড়াreading filewith open() as file: — সবসময় এভাবে খোলোalways open this wayPython-এ কোনো ভুল হলে program crash করে। কিন্তু আমরা চাই program crash না করে error সামলাক। এর জন্য try-except ব্যবহার করি।When Python encounters a mistake, the program crashes. But we want the program to handle errors without crashing. For this we use try-except.
| Exception | কখন হয়When it occurs | উদাহরণExample |
|---|---|---|
ValueError | ভুল মানWrong value | int("abc") |
ZeroDivisionError | শূন্য দিয়ে ভাগDivide by zero | 10/0 |
IndexError | List-এ নেই এমন indexIndex out of range | list[100] |
KeyError | Dict-এ নেই এমন keyKey not in dict | dict["x"] |
TypeError | ভুল টাইপে অপারেশনWrong type operation | "a" + 1 |
FileNotFoundError | ফাইল নেইFile not found | open("x.txt") |
NameError | Variable নেইVariable undefined | print(x) |
try — ঝুঁকিপূর্ণ কোড এখানেrisky code goes hereexcept — error হলে এটা চলেruns if error occurselse — কোনো error না হলেif no errorfinally — সবসময় চলে (cleanup)always runs (cleanup)raise — নিজে error তৈরি করোcreate your own errorsধরো তুমি একটা School management system বানাচ্ছো। অনেক ছাত্র আছে, প্রত্যেকের নাম, বয়স, GPA আলাদা। OOP দিয়ে একটা "Student" নামের ছাঁচ (template) বানাও, তারপর সেখান থেকে যত খুশি ছাত্র তৈরি করো।Imagine building a school management system. Many students, each with their own name, age, GPA. With OOP, make a "Student" template and create as many students as you want from it.
Class = ছাঁচ/Blueprint (যেমন: গাড়ির ডিজাইন) Object = আসল জিনিস (যেমন: সেই ডিজাইন থেকে বানানো গাড়ি) Student (Class) ├── naam: str ├── boyos: int ├── GPA: float └── parichoy(): method rahim = Student("Rahim", 20, 4.75) ← Object তৈরি karim = Student("Karim", 21, 3.90) ← আরেকটি Object
একটা class-এর সব কিছু আরেকটা class-এ পাওয়া। বাবার বৈশিষ্ট্য ছেলের মধ্যে আসার মতো।Getting everything from one class into another. Like a child inheriting parent's traits.
class — Blueprint/Template তৈরিCreate a blueprint/template__init__ — Object তৈরির সময় চলে (constructor)Runs when object is created (constructor)self — নিজের object-কে বোঝায়Refers to the current objectclass Child(Parent) — InheritanceInheritancesuper() — Parent class-এর method ডাকেCalls parent class methodsModule হলো Python কোডের একটি ফাইল যা অন্য প্রোগ্রামে import করে ব্যবহার করা যায়। Python-এ হাজার হাজার built-in এবং third-party module আছে।A module is a Python code file that you can import and use in other programs. Python has thousands of built-in and third-party modules.
import module — module ব্যবহার করোuse a modulemath — গণিতের কাজmath operationsrandom — এলোমেলো ডেটাrandom datadatetime — তারিখ ও সময়date and timeos — ফাইল সিস্টেমfile systempip install — বাইরের library ইনস্টলinstall external librariesসাধারণ loop-এর বদলে একটি compact way-তে list তৈরি করার পদ্ধতি।A compact way to create lists instead of regular loops.
map(), filter(), reduce() — functional programmingfunctional programming