SlideShare a Scribd company logo
PART 3 - Python Tutorial | For Loop In Python With Examples
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
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
EXPLAINING HOW FOR
LOOP WORKED
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
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
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
INDENTATION ERROR
LOGICAL ERROR
INDENTING UNNECESSARILY
FORGETTING THE COLON ( so tough to find )
TABS VS SPACES FOR INDENTATION
PART 3 - Python Tutorial | For Loop In Python With Examples
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
PART 3 - Python Tutorial | For Loop In Python With Examples
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
PART 3 - Python Tutorial | For Loop In Python With Examples
LOOPING THROUGH A SLICE
COPYING A LIST
PART 3 - Python Tutorial | For Loop In Python With Examples
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 (20)

Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
Qazi Shahzad Ali
 
Python tuples and Dictionary
Python   tuples and DictionaryPython   tuples and Dictionary
Python tuples and Dictionary
Aswini Dharmaraj
 
13. Pointer and 2D array
13. Pointer  and  2D array13. Pointer  and  2D array
13. Pointer and 2D array
Gem WeBlog
 
Mysql datatypes
Mysql datatypesMysql datatypes
Mysql datatypes
V.V.Vanniaperumal College for Women
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
Jasleen Kaur (Chandigarh University)
 
List in Python
List in PythonList in Python
List in Python
Sharath Ankrajegowda
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Monishkanungo
 
What is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | EdurekaWhat is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | Edureka
Edureka!
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
CGC Technical campus,Mohali
 
Python basics
Python basicsPython basics
Python basics
Jyoti shukla
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
Sujith Kumar
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
Kamal Acharya
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Hashing
HashingHashing
Hashing
kurubameena1
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
Narong Intiruk
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
Nitin Jawla
 
Strings
StringsStrings
Strings
Amrutha Rajan
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda Function
Md Soyaib
 

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

"Automata Basics and Python Applications"
"Automata Basics and Python Applications""Automata Basics and Python Applications"
"Automata Basics and Python Applications"
ayeshasiraj34
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
Panimalar Engineering College
 
powerpoint 2-13.pptx
powerpoint 2-13.pptxpowerpoint 2-13.pptx
powerpoint 2-13.pptx
JuanPicasso7
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
AnitaDevi158873
 
python_computer engineering_semester_computer_language.pptx
python_computer engineering_semester_computer_language.pptxpython_computer engineering_semester_computer_language.pptx
python_computer engineering_semester_computer_language.pptx
MadhusmitaSahu40
 
beginners_python_cheat_sheet -python cheat sheet description
beginners_python_cheat_sheet -python cheat sheet descriptionbeginners_python_cheat_sheet -python cheat sheet description
beginners_python_cheat_sheet -python cheat sheet description
NaveenVarma Chintalapati
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & lists
Marc Gouw
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
Sakith1
 
Python for loop
Python for loopPython for loop
Python for loop
Aishwarya Deshmukh
 
Pytho lists
Pytho listsPytho lists
Pytho lists
BMS Institute of Technology and Management
 
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfGE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
Guru Nanak Technical Institutions
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
KavineshKumarS
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir1
 
Practical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptxPractical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptx
trwdcn
 
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdfModule 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
SURESHA V
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentation
Nimrita Koul
 
XI_CS_Notes for strings.docx
XI_CS_Notes for strings.docxXI_CS_Notes for strings.docx
XI_CS_Notes for strings.docx
AnithaSathiaseelan1
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptx
JeromeTacata3
 
"Automata Basics and Python Applications"
"Automata Basics and Python Applications""Automata Basics and Python Applications"
"Automata Basics and Python Applications"
ayeshasiraj34
 
powerpoint 2-13.pptx
powerpoint 2-13.pptxpowerpoint 2-13.pptx
powerpoint 2-13.pptx
JuanPicasso7
 
python_computer engineering_semester_computer_language.pptx
python_computer engineering_semester_computer_language.pptxpython_computer engineering_semester_computer_language.pptx
python_computer engineering_semester_computer_language.pptx
MadhusmitaSahu40
 
beginners_python_cheat_sheet -python cheat sheet description
beginners_python_cheat_sheet -python cheat sheet descriptionbeginners_python_cheat_sheet -python cheat sheet description
beginners_python_cheat_sheet -python cheat sheet description
NaveenVarma Chintalapati
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & lists
Marc Gouw
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
Sakith1
 
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
KavineshKumarS
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir1
 
Practical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptxPractical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptx
trwdcn
 
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdfModule 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
Module 2-Lists,Tuple and Dictionary Final by Dr.SV (1).pdf
SURESHA V
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentation
Nimrita Koul
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptx
JeromeTacata3
 
Ad

More from Shivam Mitra (15)

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 python
Shivam 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 memory
Shivam 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 condition
Shivam Mitra
 
Process Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemProcess Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating system
Shivam 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 Communication
Shivam 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 interrupts
Shivam 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 Works
Shivam 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 Stack
Shivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
Shivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
Shivam 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 scores
Shivam Mitra
 
Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
Shivam 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 Examples
Shivam 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 Examples
Shivam 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 python
Shivam 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 memory
Shivam 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 condition
Shivam Mitra
 
Process Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating systemProcess Scheduling Algorithms | Interviews | Operating system
Process Scheduling Algorithms | Interviews | Operating system
Shivam 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 Communication
Shivam 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 interrupts
Shivam 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 Works
Shivam 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 Stack
Shivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
Shivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
Shivam 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 scores
Shivam Mitra
 
Ad

Recently uploaded (20)

Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 

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

  • 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
  • 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
  • 19. FORGETTING THE COLON ( so tough to find )
  • 20. TABS VS SPACES FOR INDENTATION
  • 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
  • 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
  • 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