SlideShare a Scribd company logo
1 of 39
PART 3
WORKING WITH LISTS AND FOR
LOOP
• WANT TO LEARN PYTHON PROGRAMMING? (SUBTITLES)
• SUBSCRIBE
• TELEGRAM – FreeCodeSchool
• Twitter – shivammitra4
• LinkedIn – shivammitra
• Link in description
• Playlist link in description
AGENDA
• FOR LOOP IN PYTHON
• INDENTATION IN PYTHON
• LIST COMPREHENSIONS
• SLICING A LIST
• COPYING A LIST
PRINT EACH NAME IN THE LIST
ISSUES WITH THIS APPROACH
• Repetitive code
• Need to change the code if the list size changes
FOR LOOP FOR PRINTING THE LIST
EXPLAINING HOW FOR
LOOP WORKED
AVOIDING
INDENTATION ERRORS
WHAT IS INDENTATION
• Indentation is used to make code more readability easier
• In languages like c, c++, python etc. , indentation is optional
• In Python, it is mandatory
• Python uses indentation to determine how a line, or group of lines, is
related to the rest of the program.
• Change indentation and the meaning of code changes
INDENTATION ERROR
LOGICAL ERROR
INDENTING UNNECESSARILY
FORGETTING THE COLON ( so tough to find )
TABS VS SPACES FOR INDENTATION
WHAT’S THE ACTUAL
ISSUE ?
USING SPACES VS TABS
• Spaces - consistent on every text editor
• Tabs – not consistent on every text editor
• Can be 4 spaces
• Can be 8 spaces
• Mixing tabs and spaces causes error
• I prefer using 4 spaces for indentation
• Do not type spaces 4 times
MAKING NUMERICAL
LISTS
RANGE FUNCTION
• Start to (end-1)
• Print 1 to 6
• Similar to other
programming languages
USING RANGE TO STORE A LIST OF NUMBERS
SKIPPING NUMBERS WITHIN A RANGE
PRINT MULTIPLICATION TABLE OF 5
Output – [5, 10, 15, ……….., 50]
SIMPLE STATISTICS WITH A LIST OF NUMBERS
• Maximum of a list
• Minimum of a list
• Sum of a list
LIST COMPREHENSIONS
• A list comprehension combines the for loop and the creation of new
elements into one line, and automatically appends each new
element.
• Multiplication table in one line
• Not for beginner but you will see this in others code
WORKING WITH A PART OF A LIST
• Can we access multiple list elements at one go ?
• Welcome to slice in python
• Slice of pizza ?
• Not present in all programming languages
SLICING A LIST
• To make a slice, you specify the index of the first and last elements
you want to work with.
• Like range, the last element is not considered
• List can also be of strings or
any data type
LOOPING THROUGH A SLICE
COPYING A LIST
ASSIGNMENT
• Print square of numbers from 1 to 10 using for loop
• Store it a list first and then print
• One liner code
• fruits = [‘banana’, ‘apple’, ‘watermelon’, ‘orange’]
• Print first 2 fruits ( using slicing )
• Print last 2 fruits (suing slicing )
• Print fruits at odd positions ( using for loop )
• Print fruits at even positions (using for loop )
• Paste your code in the comment
IF ELSE STATEMENTS IN
PYTHON

More Related Content

What's hot

What's hot (20)

Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python for loop
Python for loopPython for loop
Python for loop
 
Python
PythonPython
Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python made easy
Python made easy Python made easy
Python made easy
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Python basics
Python basicsPython basics
Python basics
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Python Basics.pdf
Python Basics.pdfPython Basics.pdf
Python Basics.pdf
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
 

Similar to PART 3 - Python Tutorial | For Loop In Python With Examples

VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDYVARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDYRushikesh Kolhe
 
Basic Introduction to Python Programming
Basic Introduction to Python ProgrammingBasic Introduction to Python Programming
Basic Introduction to Python ProgrammingSubashiniRathinavel
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptxmahendranaik18
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptxYusuf Ayuba
 
introduction to python
 introduction to python introduction to python
introduction to pythonJincy Nelson
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxlemonchoos
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
python presentation.pptx
python presentation.pptxpython presentation.pptx
python presentation.pptxNightTune44
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdfssuser9a6ca1
 

Similar to PART 3 - Python Tutorial | For Loop In Python With Examples (20)

VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDYVARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
 
Basic Introduction to Python Programming
Basic Introduction to Python ProgrammingBasic Introduction to Python Programming
Basic Introduction to Python Programming
 
Programming Basics.pptx
Programming Basics.pptxProgramming Basics.pptx
Programming Basics.pptx
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Python 01.pptx
Python 01.pptxPython 01.pptx
Python 01.pptx
 
Python
PythonPython
Python
 
Unit-I-PPT-1.ppt
Unit-I-PPT-1.pptUnit-I-PPT-1.ppt
Unit-I-PPT-1.ppt
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptx
 
introduction to python
 introduction to python introduction to python
introduction to python
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Chapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptxChapter7-Introduction to Python.pptx
Chapter7-Introduction to Python.pptx
 
Pa1 session 2
Pa1 session 2 Pa1 session 2
Pa1 session 2
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
06.pptx
06.pptx06.pptx
06.pptx
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
python presentation.pptx
python presentation.pptxpython presentation.pptx
python presentation.pptx
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdf
 

More from Shivam Mitra

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE InterviewsShivam Mitra
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesShivam Mitra
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesShivam Mitra
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonShivam Mitra
 
Memory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memoryMemory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memoryShivam Mitra
 
Process Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionProcess Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionShivam Mitra
 
Process Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemProcess Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemShivam Mitra
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationShivam Mitra
 
Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Shivam Mitra
 
Introduction to operating system, system calls and interrupts
Introduction to operating system, system calls and interruptsIntroduction to operating system, system calls and interrupts
Introduction to operating system, system calls and interruptsShivam Mitra
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it WorksShivam Mitra
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackShivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock MarketShivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liabilityShivam Mitra
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scoresShivam Mitra
 

More from Shivam Mitra (15)

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With Examples
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn python
 
Memory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memoryMemory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memory
 
Process Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionProcess Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race condition
 
Process Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemProcess Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating system
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
 
Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...
 
Introduction to operating system, system calls and interrupts
Introduction to operating system, system calls and interruptsIntroduction to operating system, system calls and interrupts
Introduction to operating system, system calls and interrupts
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it Works
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol Stack
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scores
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

PART 3 - Python Tutorial | For Loop In Python With Examples

  • 1.
  • 2. PART 3 WORKING WITH LISTS AND FOR LOOP • WANT TO LEARN PYTHON PROGRAMMING? (SUBTITLES) • SUBSCRIBE • TELEGRAM – FreeCodeSchool • Twitter – shivammitra4 • LinkedIn – shivammitra • Link in description • Playlist link in description
  • 3. AGENDA • FOR LOOP IN PYTHON • INDENTATION IN PYTHON • LIST COMPREHENSIONS • SLICING A LIST • COPYING A LIST
  • 4. PRINT EACH NAME IN THE LIST
  • 5. ISSUES WITH THIS APPROACH • Repetitive code • Need to change the code if the list size changes
  • 6. FOR LOOP FOR PRINTING THE LIST
  • 7.
  • 8.
  • 10.
  • 11.
  • 13. WHAT IS INDENTATION • Indentation is used to make code more readability easier • In languages like c, c++, python etc. , indentation is optional • In Python, it is mandatory • Python uses indentation to determine how a line, or group of lines, is related to the rest of the program. • Change indentation and the meaning of code changes
  • 14.
  • 15.
  • 19. FORGETTING THE COLON ( so tough to find )
  • 20. TABS VS SPACES FOR INDENTATION
  • 21.
  • 23. USING SPACES VS TABS • Spaces - consistent on every text editor • Tabs – not consistent on every text editor • Can be 4 spaces • Can be 8 spaces • Mixing tabs and spaces causes error • I prefer using 4 spaces for indentation • Do not type spaces 4 times
  • 25. RANGE FUNCTION • Start to (end-1) • Print 1 to 6 • Similar to other programming languages
  • 26.
  • 27. USING RANGE TO STORE A LIST OF NUMBERS
  • 29. PRINT MULTIPLICATION TABLE OF 5 Output – [5, 10, 15, ……….., 50]
  • 30. SIMPLE STATISTICS WITH A LIST OF NUMBERS • Maximum of a list • Minimum of a list • Sum of a list
  • 31. LIST COMPREHENSIONS • A list comprehension combines the for loop and the creation of new elements into one line, and automatically appends each new element. • Multiplication table in one line • Not for beginner but you will see this in others code
  • 32. WORKING WITH A PART OF A LIST • Can we access multiple list elements at one go ? • Welcome to slice in python • Slice of pizza ? • Not present in all programming languages
  • 33. SLICING A LIST • To make a slice, you specify the index of the first and last elements you want to work with. • Like range, the last element is not considered • List can also be of strings or any data type
  • 34.
  • 37.
  • 38. ASSIGNMENT • Print square of numbers from 1 to 10 using for loop • Store it a list first and then print • One liner code • fruits = [‘banana’, ‘apple’, ‘watermelon’, ‘orange’] • Print first 2 fruits ( using slicing ) • Print last 2 fruits (suing slicing ) • Print fruits at odd positions ( using for loop ) • Print fruits at even positions (using for loop ) • Paste your code in the comment
  • 39. IF ELSE STATEMENTS IN PYTHON