Tuple assignment, operator precedence, and comments. TRB CSI › Python Programming › Tuple assignment, operator precedence, and comments.

Tuple assignment, operator precedence, and comments.

1. Tuple Assignment

Premium — locked Intermediate 26 min 276 cards 45 programs 11 MCQs v2
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

இந்த பகுதியில் Python-ன் மூன்று முக்கியமான basic……

Premium This card is part of the premium lesson. Unlock
Definition

1. Tuple Assignment…

Premium This card is part of the premium lesson. Unlock
Definition

Tuple Assignment என்பது multiple value……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

x, y = 10, 20 இதில்: x → 10 y → 20 Simple definit……

Premium This card is part of the premium lesson. Unlock
List

1. Operator Precedence…

Premium This card is part of the premium lesson. Unlock
Explanation

Operator Precedence என்பது ஒரு expression-ல் multiple operators இருந்தால் எந்……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. Comments…

Premium This card is part of the premium lesson. Unlock

Comments என்பது programmer explanation அல்லது no……

Premium This card is part of the premium lesson. Unlock

This is a comment

Simple definition: Programmer-க்கு பு……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Tuple Assignment Normally: x = 10 y = 20 Tuple assignment பயன்படுத்தினால்: x, y = 10, 20 இரண்டும் same re……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

10 + 5 * 2 Wrong thinking: 10 + 5 = 15 15 * 2 = 30 P……

Premium This card is part of the premium lesson. Unlock

Student age

Student age

என்பது programmer note. Pytho……

Premium This card is part of the premium lesson. Unlock

மட்டுமே execute ஆகும்.…

Premium This card is part of the premium lesson. Unlock
Flow

Tuple Assignment Flow Multiple variables ↓ ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a, b, c = 10, 20, 30 Flow: a ← 10 b ← 20 c ← 30 Operator Precedence Flow Expression ↓ Parentheses check ↓ Hig……

Premium This card is part of the premium lesson. Unlock

comment

This program adds two numbers

Program
Inline comment
Explanation
Program 1

Tuple Assignment x, y = 10, 20…

Premium This card is part of the premium lesson. Unlock

Tuple assignment is also commonly called:

Multiple Assignment…

Premium This card is part of the premium lesson. Unlock
Explanation
Example

name, age, mark = "Arun", 20,……

Premium This card is part of the premium lesson. Unlock
Explanation

name, age, mark = "Arun", 20,……

Premium This card is part of the premium lesson. Unlock
Dry Run

Assignment happens based on p……

Premium This card is part of the premium lesson. Unlock
Important

Number of variables and values normally must match. Correct: x, y = 10, 20 Wrong: x, y = 10,……

Premium This card is part of the premium lesson. Unlock

Tuple Unpacking

Suppose: data = (10, 20, 30) ……

Premium This card is part of the premium lesson. Unlock
Explanation

data = (100, 200, 300) x, y, ……

Premium This card is part of the premium lesson. Unlock
Important

Tuple syntax usually uses parentheses: (10, 20, 30) But p……

Premium This card is part of the premium lesson. Unlock

Tuple Packing

Multiple values combined into……

Premium This card is part of the premium lesson. Unlock

This is called: Tuple Packing…

Premium This card is part of the premium lesson. Unlock
Concept

10 20 30 ↓ Packed together ↓ ……

Premium This card is part of the premium lesson. Unlock

Tuple Unpacking

Tuple values separated into v……

Premium This card is part of the premium lesson. Unlock
Concept

(10, 20, 30) ↓ Unpack ↓ a = 1……

Premium This card is part of the premium lesson. Unlock
Comparison
Packing vs Unpacking

Swapping Variables Using Tuple Assignment

Python-ல் two variables value……

Premium This card is part of the premium lesson. Unlock
Program
Need

Python: x, y = y, x…

Premium This card is part of the premium lesson. Unlock
Explanation

x, y = y, x…

Premium This card is part of the premium lesson. Unlock
Explanation

Initially: x = 10 y = 20 Statement: x, y = y, x Right side ……

Premium This card is part of the premium lesson. Unlock
Important

Other languages-ல் swap செய்ய temporary variable தேவைப்படலா……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Tuple Assignment: Left ↔ Righ……

Premium This card is part of the premium lesson. Unlock
Remember

1st → 1st 2nd → 2nd 3rd → 3rd…

Premium This card is part of the premium lesson. Unlock
TRB Point

Tuple assignment allows multiple vari……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

x, y = 10, 20…

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

What is tuple assignment in Python? Answer Tuple assignment allows multip……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

How do you swap two variables in Python? Answer Use tuple assi……

Premium This card is part of the premium lesson. Unlock

Definition

Operator precedence determines which operati……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

2 + 3 * 4 Both + and * are present. Python must decide: Additi……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

School maths-ல்: 2 + 3 × 4 Mu……

Premium This card is part of the premium lesson. Unlock
Explanation

Expression: 2 + 3 * 4 Operators: + * - h……

Premium This card is part of the premium lesson. Unlock
Important

Basic Operator Precedence Order For beginner/exam understanding, remember roughly: Parentheses () E……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Basic arithmetic: P E M D A S P → Parentheses E → Exponent M → Multiplication D → Divi……

Premium This card is part of the premium lesson. Unlock
Program
Example 1

Calculation: 2 * 5 = 10 10 + ……

Premium This card is part of the premium lesson. Unlock
Program
Example 2

Calculation: 10 + 2 = 12 12 *……

Premium This card is part of the premium lesson. Unlock
Important

Parentheses have very high priority. So whene……

Premium This card is part of the premium lesson. Unlock

Exponentiation Precedence

Explanation
Example

2 ** 3 Means: 2 × 2 × 2 Answe……

Premium This card is part of the premium lesson. Unlock

Why? First: 3 ** 2 = 9 Then: ……

Premium This card is part of the premium lesson. Unlock
Important

** has higher precedence than……

Premium This card is part of the premium lesson. Unlock

Same Precedence Operators

Explanation
Example

20 / 5 * 2 / and * have similar precedence level. Eva……

Premium This card is part of the premium lesson. Unlock
Important

Most same-level arithmetic operators associ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

2 ** 3 ** 2 Python interprets it l……

Premium This card is part of the premium lesson. Unlock
TRB Point

Exponentiation in Python is r……

Premium This card is part of the premium lesson. Unlock

Comparison Operator Precedence

Explanation
Example

10 + 5 > 12 Arithmetic occurs……

Premium This card is part of the premium lesson. Unlock
Output
Result

Logical Operator Precedence

Logical operators: not and or Precedence among them: no……

Premium This card is part of the premium lesson. Unlock

Why? First: False and False…

Premium This card is part of the premium lesson. Unlock
Output
Result

Then: True or False…

Premium This card is part of the premium lesson. Unlock
Output
Result
Important

When expressions become complex, don't depend only ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 1

Always Left to Right என்று நி……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

2 + 3 * 4 Python does not sim……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 2

Parentheses Ignore செய்வது (2……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 3

** same as * என்று நினைப்பது ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

2 * 3 → 6 2 ** 3 → 8…

Premium This card is part of the premium lesson. Unlock
Memory Trick

For arithmetic: Bracket Power……

Premium This card is part of the premium lesson. Unlock
Remember

() → ** → *, /, //, % → +, -…

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 1

Operator precedence determine……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 2

Parentheses can change the or……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 3

Exponentiation ** has higher ……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 4

Multiplication and division hav……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 5

Logical precedence: not > and……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

What is operator precedence? Answer Operator precedence determines the order in whic……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

How can you control precedence explicitly? ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

(2 + 3) * 4…

Premium This card is part of the premium lesson. Unlock

Definition

A comment is explanatory text included in source……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Suppose code: x = 10 y = 20 print(x + y) Later பார்க்……

Premium This card is part of the premium lesson. Unlock

Add two numbers

Now program purpose easy-ஆக ப……

Premium This card is part of the premium lesson. Unlock
Flow

Programmer writes comment ↓ Python sees # ↓ R……

Premium This card is part of the premium lesson. Unlock

comment text

Calculate total

Program
Inline comment

This program adds two numbers

Display the result

This program adds two numbers

Comment. Python does not exec……

Premium This card is part of the premium lesson. Unlock
Program
Line 3

Display the result

Comment. Line 5:…

Premium This card is part of the premium lesson. Unlock

Single-Line Comment

Most common Python comment us……

Premium This card is part of the premium lesson. Unlock
Program
Python program

The comment does not appear i……

Premium This card is part of the premium lesson. Unlock

Inline Comment

Comment can also appear after……

Premium This card is part of the premium lesson. Unlock
Program
Example
Program
Python executes

Student age

Multiple Comment Lines

If multiple comment lines are……

Premium This card is part of the premium lesson. Unlock

This program

calculates the sum

of two numbers

Important

Python does not have a special dedicated block-comment synt……

Premium This card is part of the premium lesson. Unlock

comment line 1

comment line 2

comment line 3

Important

You may see: """ This is some text across multiple lines """ This is technically a triple……

Premium This card is part of the premium lesson. Unlock

Docstring

A docstring documents: Module……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Here: """Return the sum of tw……

Premium This card is part of the premium lesson. Unlock
Comparison
Comment vs Docstring
Important

Why Comments Are Useful Comments help in: Understanding code ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 1

Comment output-ல் வரும் என்று……

Premium This card is part of the premium lesson. Unlock

Hello

Hello does not print.…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 2

// comment என்று நினைப்பது In……

Premium This card is part of the premium lesson. Unlock

comment

Common Mistake
Error 3

# inside a string comment என்……

Premium This card is part of the premium lesson. Unlock
Program
Example

Why? Because # is inside quotes……

Premium This card is part of the premium lesson. Unlock

= Comment

→ Note for humans

Code → Instruction for Python…

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 1

Python single-line comments b……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 2

Comments are ignored during n……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 3

Comments improve code readabi……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 4

Triple-quoted strings are not……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 5

A docstring is used to docume……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

How do you write comments in Python? Answer Single-line comments begin w……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

What is the difference between a comment and a docstring? Answer A comment uses # and……

Premium This card is part of the premium lesson. Unlock
Comparison
Tuple Assignment vs Operator Precedence vs Comments
Important

Three Concepts in One Program…

Premium This card is part of the premium lesson. Unlock

Assign two values

x, y = 10, 20…

Premium This card is part of the premium lesson. Unlock

Multiplication is evaluated before addition

Here: x, y = 10, 20 → Tuple A……

Premium This card is part of the premium lesson. Unlock

Assign two values

→ Comment…

Premium This card is part of the premium lesson. Unlock

Why? First: y * 2 20 * 2 = 40……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is an example of tuple ……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the value of y? x, y ……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? x, y = 5,……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the result? 2 + 3 * 4…

Premium This card is part of the premium lesson. Unlock
MCQ

What is the result? (2 + 3) *……

Premium This card is part of the premium lesson. Unlock
MCQ

Which operator has higher pre……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the result? 2 ** 3…

Premium This card is part of the premium lesson. Unlock
MCQ

Which symbol starts a Python ……

Premium This card is part of the premium lesson. Unlock
MCQ 9

What is the output?…

Premium This card is part of the premium lesson. Unlock

print("Hello")

B. Python C. Hello Python D. ……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? print("#H……

Premium This card is part of the premium lesson. Unlock

is inside a string, so it is not treated as a comment.

MCQ

What is the output? a, b, c =……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the result? 10 + 20 /……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 1

Assign three values using one sta……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 2

Swap these variables: a = 100……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 3

Find the output: x, y = 5, 3 print(……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 4

Find the output: print((5 + 3……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 5

Find the output: print(2 ** 3……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 6

Write a comment explaining this……

Premium This card is part of the premium lesson. Unlock

Add two numbers

Practice
Practice 7

What happens? x, y = 10, 20, 30 Answer: The num……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 8

Identify: data = 10, 20, 30 A……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 9

Identify: a, b, c = data Answ……

Premium This card is part of the premium lesson. Unlock

First value

Second value

Answer: 52…

Premium This card is part of the premium lesson. Unlock
Summary

Tuple assignment assigns multiple values to multiple variables in one statement. x, y = 10, 20 is tuple assig……

Premium This card is part of the premium lesson. Unlock

inside a string is not a comment.

Multiple comment lines can each begin with #. Doc……

Premium This card is part of the premium lesson. Unlock
Quick Revision

x, y = 10, 20 → Tuple Assignment data = 10, 20 → Tuple Packing x, y = data ……

Premium This card is part of the premium lesson. Unlock
Quick Revision

- / // % → Before + -…

Premium This card is part of the premium lesson. Unlock
Quick Revision

2 + 3 * 4 → 14 (2 + 3) * 4 → ……

Premium This card is part of the premium lesson. Unlock

→ Python comment

Comments → Not executed "#Hello" → String, not comment Mem……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program