Lädt...


🔧 Day 16 - Slicing,for loop and nested loop


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Slicing:

Slicing is a programming technique used in Python to extract a portion of a sequence. By specifying a range of indices, you can retrieve specific parts of the sequence without altering the original data.

Example:

name=[2,8]

Step operator:

A step operator refers to the ability to specify an increment for iteration in loops. In Python, this is often used with the range() function, which allows specifying a step to control how the loop variable changes after each iteration.

Example:

name[2:8:3]
3 is a step operator.

Program using two variable:

start,end= 1,6
while end>1:
    for num in range(start,end):
        print(num, end=" ")
    print()
    end-=1   

Same program using one variable:

end= 6
while end>1:
    for num in range(1,end):
        print(num, end=" ")
    print()
    end-=1  

*Same program without using variable or using nested loop:
*

for end in range(6,1,-1):
    for num in range(1,end):
        print(num, end=" ")
    print()  

Output:

1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 

Nested loop:

A nested for loop is a loop inside another loop.

Syntax:

for outer in outer_iterable:
    for inner in inner_iterable:

1.The outer loop runs first.
2.For every iteration of the outer loop, the inner loop runs completely.
3.When the inner loop finishes, the outer loop proceeds to its next iteration.

for row in range(2,7):
    for col in range(1,row):
        print(col, end=' ')
    print()
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
for row in range(5):
    for col in range(5-row):
        print(col+1, end=' ')
    print()
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
for row in range(5):
    for col in range(5-row):
        print((col+1)*2, end=' ')
    print()
2 4 6 8 10 
2 4 6 8 
2 4 6 
2 4 
2 
for row in range(5):
    for col in range(5-row):
        print((col+1)*(row+1), end=' ')
    print()
1 2 3 4 5 
2 4 6 8 
3 6 9 
4 8 
5 

Task:

(https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3v84djylxrixjnllx8hq.jpg)

for row in range(5):
    for col in range(5-row):
        print((col+1)*3, end=" ")
    print()

3 6 9 12 15 
3 6 9 12 
3 6 9 
3 6 
3 
for row in range(5):
    for col in range(row+1):
        print(5-col, end=' ')
    print()
5 
5 4 
5 4 3 
5 4 3 2 
5 4 3 2 1 
...

🔧 Day 16 - Slicing,for loop and nested loop


📈 32.9 Punkte
🔧 Programmierung

📰 Nested Dictionary Python — A Complete Guide to Python Nested Dictionaries


📈 31.18 Punkte
🔧 AI Nachrichten

🔧 Day 17 - Nested for loop and Pattern Programs


📈 28.77 Punkte
🔧 Programmierung

🔧 Python Day-18 Nested for loop -pattern,OOPS-Object Oriented Programming System


📈 27.51 Punkte
🔧 Programmierung

🕵️ Mozilla Firefox up to 62.x Nested Event Loop denial of service


📈 23.62 Punkte
🕵️ Sicherheitslücken

🔧 Nested while loop


📈 23.62 Punkte
🔧 Programmierung

🔧 NESTED WHILE LOOP


📈 23.62 Punkte
🔧 Programmierung

🔧 How I tried to understand inside a Nested For Loop


📈 23.62 Punkte
🔧 Programmierung

🔧 Day 63 of 100 Days of Code: Navigating Nested Objects


📈 19.48 Punkte
🔧 Programmierung

🔧 Python day-28 Dictionary, Frequency of character using nested loops


📈 19.48 Punkte
🔧 Programmierung

🔧 Day-28 Dictionary, Frequency of character using nested loops


📈 19.48 Punkte
🔧 Programmierung

🔧 Day-28 Dictionary, Frequency of character using nested loops


📈 19.48 Punkte
🔧 Programmierung

🍏 Grab up to 70% off Solo Loop and Braided Solo Loop Apple Watch bands


📈 17.31 Punkte
🍏 iOS / Mac OS

⚠️ [dos] WebKit - UXSS via XSLT and Nested Document Replacements


📈 16.85 Punkte
⚠️ PoC

⚠️ #0daytoday #WebKit - UXSS via XSLT and Nested Document Replacements Exploit [dos #exploits #0day #Exploit]


📈 16.85 Punkte
⚠️ PoC

🔧 ARM Series #8: Linked and Nested Templates | The DevOps Lab


📈 16.85 Punkte
🔧 Programmierung

🔧 Nested IoT Edge devices and offline dashboards | Internet of Things Show


📈 16.85 Punkte
🔧 Programmierung

🔧 Typescript Generate Full Path Type And Get Value Type Of Nested Object


📈 16.85 Punkte
🔧 Programmierung

🔧 C++ if, if...else and Nested if...else


📈 16.85 Punkte
🔧 Programmierung

🐧 How to Understand and Use Nested Classes in C#


📈 16.85 Punkte
🐧 Linux Tipps

🔧 Nested if and Multi-Way if-else Statements


📈 16.85 Punkte
🔧 Programmierung

🔧 Understanding Apollo Client Cache: How to Manage and Update Nested Data Structures Effectively


📈 16.85 Punkte
🔧 Programmierung

🔧 SQL Course: Many-to-many relationship and Nested Joins.


📈 16.85 Punkte
🔧 Programmierung

🔧 Working with the Angular tree: Flat vs. nested trees and more


📈 16.85 Punkte
🔧 Programmierung

🔧 Rails Designer v1.3: Two New Components and Nested Forms Utility 🤯


📈 16.85 Punkte
🔧 Programmierung

🔧 Immer : Clear understanding of how to handle nested state objects with Immer in React and TypeScript


📈 16.85 Punkte
🔧 Programmierung

🔧 NeoHaskell v0.5.0 - HTTP, TOML, Nested Actions Now Executed and Major Refactoring


📈 16.85 Punkte
🔧 Programmierung

📰 Seamless Parsing of Nested JSON and Schema Evolution in DLT Without Restarting Pipelines


📈 16.85 Punkte
🔧 AI Nachrichten

🔧 Dive into Next.js App Router: Building Dynamic, Nested, and Static Pages


📈 16.85 Punkte
🔧 Programmierung

🔧 Difference Between Varray and Nested Table in PLSQL


📈 16.85 Punkte
🔧 Programmierung

🔧 Differences Between VARRAY, Nested Table, and Associative Array in PL/SQL


📈 16.85 Punkte
🔧 Programmierung

🔧 Java Inner Classes and Nested Classes


📈 16.85 Punkte
🔧 Programmierung

matomo