Table of Contents

    Class - XII: SEMESTER – III: Unit – 1: Python Programming: Section 4: Expressions, statement, type conversion, and input/output

    Python Programming: Expressions, Statements, Type Conversion এবং Input/Output

    ১. Expression কী?

    Python-এ Expression হলো এমন একটি combination যেখানে variable, constant এবং operator ব্যবহার করে একটি value তৈরি করা হয়।

    উদাহরণ:

    x = 10 + 5

    এখানে 10 + 5 একটি Expression এবং এর result হলো 15।

    আরও উদাহরণ:

    • a * b
    • (x + y) / 2
    • num ** 2

    ২. Statement কী?

    Python-এ একটি complete instruction বা command কে Statement বলা হয়।

    উদাহরণ:

    x = 10
    print(x)

    এখানে প্রতিটি line একটি Statement।

    Python-এ semicolon ব্যবহার না করলেও Statement valid থাকে।

    ৩. Operator Precedence (অপারেটরের অগ্রাধিকার)

    একটি Expression এ একাধিক operator থাকলে কোনটি আগে execute হবে তা নির্ধারণ করে Operator Precedence।

    Python Operator Precedence (সংক্ষেপে):

    • () → সর্বোচ্চ
    • ** (Power)
    • *, /, %, //
    • +, -
    • = → সর্বনিম্ন

    উদাহরণ:

    result = 10 + 5 * 2
    print(result)

    এখানে প্রথমে multiplication হবে (5*2=10), তারপর addition (10+10=20)

    Bracket Example:

    result = (10 + 5) * 2
    print(result)

    এখানে আগে bracket → তারপর multiplication → Result = 30

    ৪. Expression Evaluation

    Expression step-by-step execute হয়ে final value তৈরি করার process কে Expression Evaluation বলা হয়।

    উদাহরণ:

    x = 5 + 10 / 2
    print(x)

    Evaluation Steps:

    1. 10 / 2 = 5
    2. 5 + 5 = 10

    Final Output: 10

    ৫. Type Conversion কী?

    এক data type থেকে অন্য data type এ convert করাকে Type Conversion বলা হয়।

    Python-এ দুই ধরনের conversion আছে:

    • Implicit Conversion
    • Explicit Conversion

    ৬. Implicit Type Conversion

    Python automatically ছোট type কে বড় type এ convert করে।

    x = 10
    y = 2.5
    
    result = x + y
    print(result)

    এখানে int → float এ convert হয়েছে।

    ৭. Explicit Type Conversion (Casting)

    Programmer যখন manually conversion করে তখন তাকে Explicit Conversion বলা হয়।

    x = "10"
    y = int(x)
    
    print(y + 5)

    এখানে string থেকে int এ convert করা হয়েছে।

    Python casting functions:

    • int()
    • float()
    • str()

    ৮. Console Input নেওয়া

    Python-এ user input নেওয়ার জন্য input() function ব্যবহার করা হয়।

    name = input("আপনার নাম লিখুন: ")
    print("স্বাগতম", name)

    Important: input() সবসময় string return করে।

    Number Input Example:

    num = int(input("সংখ্যা লিখুন: "))
    print(num * 2)

    ৯. Output দেখানো

    Python-এ output দেখানোর জন্য print() function ব্যবহার করা হয়।

    print("Hello World")

    Multiple Output:

    age = 25
    print("Age =", age)

    Formatted Output:

    name = "Rahim"
    age = 20
    
    print(f"Name: {name}, Age: {age}")

    ১০. Complete Real Example

    # User input নিচ্ছে
    a = int(input("প্রথম সংখ্যা: "))
    b = int(input("দ্বিতীয় সংখ্যা: "))
    
    # Expression
    sum_value = a + b
    
    # Output
    print("যোগফল:", sum_value)
    
    # Type Conversion + Average
    avg = (a + b) / 2
    print("গড়:", avg)

    এখানে ব্যবহৃত হয়েছে:

    • Expression
    • Statement
    • Operator
    • Type Conversion
    • Input
    • Output

    উপসংহার

    Python programming শিখতে গেলে Expressions, Statements, Operator Precedence, Type Conversion এবং Input/Output খুবই গুরুত্বপূর্ণ।

    এগুলো ভালোভাবে বুঝতে পারলে আপনি সহজেই complex programming logic তৈরি করতে পারবেন।

    বিশেষ করে real-world application develop করার জন্য এই concepts গুলো strong হওয়া জরুরি।