Lesson – 103 : Python માં Control Statements, String Manipulation, Lists, Tuple અને Sets
Python એક લોકપ્રિય અને multi-purpose programming language છે, જેમાં data handling, looping, logic building અને string processing માટે મજબૂત structure આપવામાં આવ્યું છે.
🟩 1. Control Statements in Python (કંટ્રોલ સ્ટેટમેન્ટ્સ)
Control Statements એ પ્રોગ્રામના flow ને નિયંત્રિત કરવા માટે વપરાય છે. Python માં મુખ્ય ત્રણ પ્રકારના control statements છે:
➤ 1. break Statement
break નો ઉપયોગ loopને તાત્કાલિક બંધ કરવા માટે થાય છે.
➤ 2. continue Statement
continue હાલનું iteration સ્કિપ કરીને આગળના iteration તરફ લઈ જાય છે.
➤ 3. pass Statement
pass એક empty statement છે જે future code માટે placeholder તરીકે કામ કરે છે.
🟦 2. String Manipulation in Python (સ્ટ્રિંગ મેન્યુપ્યુલેશન)
String એ characters ની sequence છે અને Python માં તે immutable હોય છે.
✨ સામાન્ય string functions
| Method | Description |
|---|---|
upper() |
તમામ અક્ષરો uppercase કરે |
lower() |
lowercase કરે |
replace() |
શબ્દ અથવા અક્ષર બદલે |
split() |
string ને list માં વહેંચે |
strip() |
આગળ-પાછળનો space દૂર કરે |
✔ Example:
🟨 3. Lists in Python (લિસ્ટ)
List એ mutable, ordered collection છે જેમાં જુદા જુદા data types રાખી શકાય છે.
✔ List Example:
✨ મહત્વના list functions:
| Method | Work |
|---|---|
append() |
છેલ્લા ભાગે value ઉમેરે |
insert() |
કોઈપણ index પર value ઉમેરે |
remove() |
value દૂર કરે |
pop() |
છેલ્લી value અથવા index value કાઢે |
sort() |
list sort કરે |
🟧 4. Tuple in Python (ટ્યુપલ)
Tuple, list જેવી જ છે, પરંતુ immutable હોવાથી values બદલી શકાતી નથી.
✔ Example:
Tuple ઓળખાણ:
-
parentheses
()વપરાય છે -
fast & memory efficient
-
data fix રાખવા યોગ્ય
🟥 5. Sets in Python (સેટ્સ)
Set એ unique elements નું unordered collection છે.
✔ Example:
✨ Set Operations:
| Operation | Meaning |
|---|---|
union() |
બે set ના બધાજ unique values |
intersection() |
common values |
difference() |
એકમાંથી બીજાને ઘટાડે |
Python માં control statements પ્રોગ્રામના flow ને નિયંત્રિત કરે છે, જ્યારે string manipulation ટેક્સ્ટ પ્રક્રિયા સરળ બનાવે છે. List અને Tuple data ને સંગ્રહિત કરવા માટે બહુ ઉપયોગી છે, જ્યારે Set unique values માટે ઉત્તમ છે. આ concepts Python programming નો આધાર છે અને તેમાં નિપુણતા મેળવીને તમે મજબૂત logic અને પ્રોગ્રામ બનાવી શકો છો.