প্রথমত দেখি, পাইথন কী ??
পাইথনের ক্রিয়েটর অনুযায়ি ‘Guido van Rossum’ পাইথন হচ্ছে,
“high-level programming language, and its core design philosophy is all about code readability and a syntax which allows programmers to express concepts in a few lines of code.”
আমার জন্যে – পাইথন শেখার প্রথম এবং প্রধানত কারন এটা ছিলো যে, এটি সুন্দর প্রোগ্রামিং লাঙ্গুয়েজ । এটি সত্যিই ছিলো যে, আমি যা ভেবেছিলাম যেমন অনেক সাধারন কোড ছিলো এবং কোডগুলা আমার চিন্তাধারাকে প্রকাশ করে ।
আর একটি কারন ছিল যে, পাইথনের কোডিং করে বিভিন্ন সমস্যাই একাধিক উপায়ে ব্যাবহার করতে পারি । যেমন – ডাটা সায়েন্স , ওয়েব ডেভেলপমেন্ট এবং মেশিন লার্নিং এর সব চমৎকার উজ্জ্বল বার্তাময় কাজগুলা । Quora, Pinterest and Spotify সহ আরো অনেকে পাইথন ব্যাবহার করেছে তাদের backend ওয়েব ডেভেলপমেন্ট এর কাজে ।
তাহলে এবার শুরু করা যাক — !
The Basics :
1. Variables :
তুমি এখন চিন্তা করতে পারো ভেরিয়েবল নিয়ে কিভাবে একটা শব্দের মাধ্যেমে কোনো একটা মান সঞ্চয় করে ? বিষয়টা মটেও জটিল না ।
পাইথনের মধ্যে, ভেরিয়েবল ডিফাইন এবং ভেলু সেট করা খুব সহজ এবং সত্যিই সহজ । কল্পনার মধ্যে গিয়ে ভাবতে থাকো “1” একটি ভেলু আমি একটি ভেরিয়েবলে রাখতে চায় । তাহলে কি করবো এমন করতে থাকুন –
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
one = 1
এটা কতটা সহজ ছিলো ? তুমি শুধুমাত্র “1” একটা ভেলু অ্যাসাইন করেছো ভেরিয়েবল “one” এর মধ্যে ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
two = 2 some_number = 10000
তুমি যদি চাও অন্য ভেরিয়েবল এর জন্যে আলাদা ভেলু রাখতে চাও সেটাও তুমি করতে পারবে । উপরের টেবিলে তুমি দেখতে পাচ্ছো যে, ভেরিয়েবল “2” একটা ইন্টিজার সংখ্যা সঞ্চয় করে এবং “some_number” ভেরিয়েবল “10000” ভেলু সঞ্চয় করে ।
ইন্টিজার ছাড়াও আমরা booleans (True / False), string, float এবং অন্যান্য অনেক ধরনের টাইপ ব্যাবহার করতে পারি ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
# booleans true_boolean = True false_boolean = False # string my_name = "RD Islam Nasim" # float book_price = 15.80
2. Control Flow: conditional statements :
“If” ব্যাবহার করা হয় সে সকল স্টেটমেন্ট এর ক্ষেত্রে যেখানে True or False এর এক্সপ্রেসন থাকে । যদি এটা সত্য হয় তাহলে “if” স্টেটমেন্ট এর মধ্যে কাজ করে । উদাহরন হিসাবে দেখা যেতে পারে –
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
if True: print("Hello Python If") if 2 > 1: print("2 is greater than 1")
“2 is greater than 1” , তাই “print” code is executed.
“else” স্টেটমেন্ট ঠিক তখনই কার্যকর হবে যখন “if” স্টেটমেন্ট মিথ্যা হবে ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
if 1 > 2: print("1 is greater than 2") else: print("1 is not greater than 2")
“1 is not greater than 2”, তাই কোড এর মধ্যে “else” স্টেটমেন্টটা কার্যকর হবে ।
আমরা এবার “elif” স্টেটমেন্টও ব্যাবহার করতে পারি । যেমন – নিচের কোড গুলা দেখো তাহলে ভালো ধারনা হবে ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
if 1 > 2: print("1 is greater than 2") elif 2 > 1: print("1 is not greater than 2") else: print("1 is equal to 2")
3. Looping/Iterator :
পাইথনে আমরা বিভিন্ন উপায়ে লুপিং করতে পারি । আমি ২টা সম্পর্কে কথা বলবো ঃ
- একটা হচ্ছে “while”
- অন্যটা “for” লুপ
while লুপিং ঃ যখন স্টেটমেন্টটি সত্য – তখন ব্লকের ভিতরে কোডটি চলবে এবং ঘটনাটি সত্য বলে বিবেচিত হবে । সুতরাং নিচের কোডটিতে ১ থেকে ১০ পর্যন্ত লিখে দেখাবে । দেখি কি হয় ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
num = 1 while num <= 10: print(num) num += 1
while লুপের মধ্যে থাকে “loop condition” । যদি এটা সত্য হয় তাহলে অনবরত লুপিং চলতেই থাকবে । আমরা উপরের উদাহরন এর মাধ্যমে দেখতে পারি – যখন num এর ভেলু ১১ ছিলো তখন লুপ কন্ডিশান False ছিলো ।
আমরা অন্য আরেকটি সাধারন কোড দেখলে ভালো ধারনা আসবে বলে আশা করছি ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
loop_condition = True while loop_condition: print("Loop Condition keeps: %s" %(loop_condition)) loop_condition = False
এই লুপ কন্ডিশান True । তাই যতক্ষন না পর্যন্ত আমরা সেট করছি তার ভেলু হিসাবে False ।
For লুপিং ঃ তুমি এখন একটা ভেরিয়েবল ডিক্লেয়ার করতে পারো যার নাম দাও “num” এবং “for” লুপিং এর মাধ্যেমে এই লুপিংকে চালিয়ে নিয়ে যাও । নিচের কোডের দিকে তাকালে আমরা দেখতে পাবো যে, এটি আগের মতই ১ থেকে ১০ পর্যন্ত প্রিন্ট করেছে ।
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
for i in range(1, 11): print(i)
দেখেছো ?? এটা কত সহজ । উপরের কোডের রেঞ্জ ১ থেকে শুরু হয়ে ১১ তম উপাদান (
10
is the 10
th element)