SlideShare a Scribd company logo
PyLecture4 -Python Basics2-
 Write following python script with your text
editor.
 Then, run ‘python your_script.py’
 If you got ‘Hello World’, go on to the next
slide.
def main():
print ‘Hello World’
if __name__ == ‘__main__’:
main()
 Lists – compound data type
l = [1,2,3,5] # defines a list contains 1, 2, 3, 5
print l[0] # getting a value
l[0] = 6 # setting a value
l.append(7) # adding to list
print l # will print ‘[6, 2, 3, 5, 7]’
l.extend([8, 9, 10]) # connecting another list
print l # will print ‘[6, 2, 3, 5, 7, 8, 9, 10]’
print range(3) # stops at 2
print range(1, 3) # starts at 1 and stops at 2
print range(0, 5, 2) # start: 1 stop: 4 and steps by 2
 Create following lists with range function.
1. [0, 1, 2, 3, 4]
2. [3, 4, 5, 6, 7]
3. [3, 6, 9, 12, 15, 18]
4. [2, 4, 6, 8, 12, 16, 20] hint: use + operator
 Answer:
1. range(5)
2. range(3, 8)
3. range(3, 21, 3)
4. range(2, 10, 2) + range(12, 24, 4)
 Dictionaries – compound data type
 Found in other languages as “map”,
“associative memories”, or “associative arrays”
 Lists vs Dictionaries
› You can use only integer number as index on lists
Like a[0], a[-1]
› You can use integer numbers and strings as key on
dictionaries(if its value exists)
Like d[0], d[‘foo’], d[‘bar’]
 Creating a dictionary
tel = {‘John’:8000, ‘Jane’:8001, ‘Joe’:8002}
 Adding key and value
tel[‘Joan’] = 8003
 Getting value from key
tel[‘Jane’]
 Setting value from key
tel[‘Joe’] = 0004
 Removing value from key
del tel[‘John’]
 Getting key list of a dictionary
tel.keys()
 Crate a dictionary from two lists
names = [‘John’, ‘Jane’, ‘Joe’]
tel = [8000, 8001, 8002]
tel = dict(zip(names, tel))
 Create a dictionary that
› Keys are [0, 1, …, 10]
› Values are (key) * 2
› i.e. d[0]=0, d[1]=2, d[2]=4, …, d[10]=20
 Answer:
k = range(11)
v = range(0, 11*2, 2)
d = dict(zip(k, v))
 Logical Operator
 if statements
 for statements
 Compares two values
print 1 < 2
print 1 > 2
print 1 == 2
print 1 <= 2
print 1 >= 2
 And, Or, and Not
print 1 < 2 and 1 == 2
print 1 < 2 or 1 > 2
print not 1 == 2
x = int(raw_input(‘value of x: ’))
if x < 0:
print(‘x is negative’) # must indent
elif x > 0:
print(‘x is positive’)
else:
print(‘x is not positive neither negative’)
print(‘i.e. x is zero’)
For integer variable named ‘x’,
› Print ‘fizz’ if x can be divided by 3
› Print ‘buzz’ if x can be divided by 5
(e.g. if x is 10, print ‘buzz’, x is 15, print ‘fizz buzz’)
(hint: use % operator(e.g. 10 % 3 = 1, 14 % 5 = 4))
x = int(raw_input('x value:'))
if x % 3 == 0:
print 'fizz'
if x % 5 == 0:
print 'buzz'
n = int(raw_input(‘list length: ’))
l = []
for i in range(n): # for each number in (0…n-1)
l.append(raw_input(‘%dth word: ’ % i))
for w in l: # for each word in your list
print w
Create a list only contains
› Multiple of 3 or 5 (3, 5, 6, 9…)
› Between 1 and 20
i.e. [3, 5, 6, 9, 10, 12, 15, 18, 20]
l = []
for i in range(1, 21):
if i % 3 == 0 or i % 5 == 0:
l.append(i)
print l
 Defining a function
def add(a, b):
return a + b
 Calling the function
print add(10, 2)
 Recursive call
def factorial(n):
if n <= 0:
return 1
else:
return n * factorial(n-1)
 Find the 10-th Fibonacci sequence
› Fibonacci sequence is
 0, 1, 1, 2, 3, 5, 8, …
 The next number is found by adding up the two
numbers before it(e.g. 5th number 3 = 2 + 1).
def fib(n):
if n <= 1:
return 0
elif n == 2:
return 1
else:
return fib(n-1) + fib(n-2)
print fib(10)

More Related Content

What's hot (20)

令和から本気出す
令和から本気出す令和から本気出す
令和から本気出す
Takashi Kitano
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland
 
{tidytext}と{RMeCab}によるモダンな日本語テキスト分析
{tidytext}と{RMeCab}によるモダンな日本語テキスト分析{tidytext}と{RMeCab}によるモダンな日本語テキスト分析
{tidytext}と{RMeCab}によるモダンな日本語テキスト分析
Takashi Kitano
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
Python PCEP Operations On Lists
Python PCEP Operations On ListsPython PCEP Operations On Lists
Python PCEP Operations On Lists
IHTMINSTITUTE
 
Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
Webmontag Berlin
 
Python idioms
Python idiomsPython idioms
Python idioms
Sofian Hadiwijaya
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
SeongGyu Jo
 
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
Takashi Kitano
 
PHP string-part 1
PHP string-part 1PHP string-part 1
PHP string-part 1
monikadeshmane
 
Favouring Composition - The Groovy Way
Favouring Composition - The Groovy WayFavouring Composition - The Groovy Way
Favouring Composition - The Groovy Way
Naresha K
 
WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHP
andrewnacin
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver){tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
Takashi Kitano
 
Database performance 101
Database performance 101Database performance 101
Database performance 101
Leon Fayer
 
Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017
Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017
Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017
Codemotion
 
令和から本気出す
令和から本気出す令和から本気出す
令和から本気出す
Takashi Kitano
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland
 
{tidytext}と{RMeCab}によるモダンな日本語テキスト分析
{tidytext}と{RMeCab}によるモダンな日本語テキスト分析{tidytext}と{RMeCab}によるモダンな日本語テキスト分析
{tidytext}と{RMeCab}によるモダンな日本語テキスト分析
Takashi Kitano
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
Python PCEP Operations On Lists
Python PCEP Operations On ListsPython PCEP Operations On Lists
Python PCEP Operations On Lists
IHTMINSTITUTE
 
Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
Webmontag Berlin
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
SeongGyu Jo
 
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
Takashi Kitano
 
Favouring Composition - The Groovy Way
Favouring Composition - The Groovy WayFavouring Composition - The Groovy Way
Favouring Composition - The Groovy Way
Naresha K
 
WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHP
andrewnacin
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver){tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
Takashi Kitano
 
Database performance 101
Database performance 101Database performance 101
Database performance 101
Leon Fayer
 
Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017
Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017
Templating you're doing it wrong - Nikolas Martens - Codemotion Amsterdam 2017
Codemotion
 

Viewers also liked (14)

Oratoria
OratoriaOratoria
Oratoria
Paula Andrea
 
How Docker didn't invent containers (Docker Meetup Brno #1)
How Docker didn't invent containers (Docker Meetup Brno #1)How Docker didn't invent containers (Docker Meetup Brno #1)
How Docker didn't invent containers (Docker Meetup Brno #1)
Pavel Snajdr
 
KEPERCAYAAN GURU
KEPERCAYAAN GURUKEPERCAYAAN GURU
KEPERCAYAAN GURU
NurAlias91
 
công ty thiết kế phim quảng cáo nhanh nhất
công ty thiết kế phim quảng cáo nhanh nhấtcông ty thiết kế phim quảng cáo nhanh nhất
công ty thiết kế phim quảng cáo nhanh nhất
evette568
 
Top 8 internet marketing specialist resume samples
Top 8 internet marketing specialist resume samplesTop 8 internet marketing specialist resume samples
Top 8 internet marketing specialist resume samples
hallerharry710
 
Galaxy royale
Galaxy royaleGalaxy royale
Galaxy royale
Dhra Sharma
 
Ace city
 Ace city  Ace city
Ace city
Dhra Sharma
 
La Representacion Grafica
La Representacion GraficaLa Representacion Grafica
La Representacion Grafica
Alejandra Gamboa
 
Carlito N. Siervo Jr
Carlito N. Siervo JrCarlito N. Siervo Jr
Carlito N. Siervo Jr
Carlito Jr Siervo
 
Terril Application Developer
Terril Application DeveloperTerril Application Developer
Terril Application Developer
Terril Thomas
 
when you forget your password
when you forget your passwordwhen you forget your password
when you forget your password
Corneliu Dascălu
 
Advertising agencies
Advertising agenciesAdvertising agencies
Advertising agencies
Shrey Oberoi
 
How Docker didn't invent containers (Docker Meetup Brno #1)
How Docker didn't invent containers (Docker Meetup Brno #1)How Docker didn't invent containers (Docker Meetup Brno #1)
How Docker didn't invent containers (Docker Meetup Brno #1)
Pavel Snajdr
 
KEPERCAYAAN GURU
KEPERCAYAAN GURUKEPERCAYAAN GURU
KEPERCAYAAN GURU
NurAlias91
 
công ty thiết kế phim quảng cáo nhanh nhất
công ty thiết kế phim quảng cáo nhanh nhấtcông ty thiết kế phim quảng cáo nhanh nhất
công ty thiết kế phim quảng cáo nhanh nhất
evette568
 
Top 8 internet marketing specialist resume samples
Top 8 internet marketing specialist resume samplesTop 8 internet marketing specialist resume samples
Top 8 internet marketing specialist resume samples
hallerharry710
 
Terril Application Developer
Terril Application DeveloperTerril Application Developer
Terril Application Developer
Terril Thomas
 
when you forget your password
when you forget your passwordwhen you forget your password
when you forget your password
Corneliu Dascălu
 
Advertising agencies
Advertising agenciesAdvertising agencies
Advertising agencies
Shrey Oberoi
 
Ad

Similar to PyLecture4 -Python Basics2- (20)

cs class 12 project computer science .docx
cs class 12 project computer science  .docxcs class 12 project computer science  .docx
cs class 12 project computer science .docx
AryanSheoran1
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
juzihua1102
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
Pedro Rodrigues
 
25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator
PravinDhanrao3
 
Python basic
Python basic Python basic
Python basic
sewoo lee
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
AnirudhaGaikwad4
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
HongAnhNguyn285885
 
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdfPython Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
zayanchutiya
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
omprakashmeena48
 
Python slide
Python slidePython slide
Python slide
Kiattisak Anoochitarom
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
TURAGAVIJAYAAKASH
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
Verxus
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
MeghanaDBengalur
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
ElNew2
 
Practical File Grade 12.pdf
Practical File Grade 12.pdfPractical File Grade 12.pdf
Practical File Grade 12.pdf
dipanshujoshi8869
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
Siva Arunachalam
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
ChandanVatsa2
 
cs class 12 project computer science .docx
cs class 12 project computer science  .docxcs class 12 project computer science  .docx
cs class 12 project computer science .docx
AryanSheoran1
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
juzihua1102
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
Pedro Rodrigues
 
25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator
PravinDhanrao3
 
Python basic
Python basic Python basic
Python basic
sewoo lee
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
HongAnhNguyn285885
 
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdfPython Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
zayanchutiya
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
omprakashmeena48
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
TURAGAVIJAYAAKASH
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
Verxus
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
ElNew2
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
Siva Arunachalam
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
ChandanVatsa2
 
Ad

More from Yoshiki Satotani (7)

Basic practice of R
Basic practice of RBasic practice of R
Basic practice of R
Yoshiki Satotani
 
Basic use of Python (Practice)
Basic use of Python (Practice)Basic use of Python (Practice)
Basic use of Python (Practice)
Yoshiki Satotani
 
Basic use of Python
Basic use of PythonBasic use of Python
Basic use of Python
Yoshiki Satotani
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
Yoshiki Satotani
 
PyLecture2 -NetworkX-
PyLecture2 -NetworkX-PyLecture2 -NetworkX-
PyLecture2 -NetworkX-
Yoshiki Satotani
 
PyLecture1 -Python Basics-
PyLecture1 -Python Basics-PyLecture1 -Python Basics-
PyLecture1 -Python Basics-
Yoshiki Satotani
 
PyLecture3 -json-
PyLecture3 -json-PyLecture3 -json-
PyLecture3 -json-
Yoshiki Satotani
 

Recently uploaded (20)

Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 

PyLecture4 -Python Basics2-

  • 2.  Write following python script with your text editor.  Then, run ‘python your_script.py’  If you got ‘Hello World’, go on to the next slide. def main(): print ‘Hello World’ if __name__ == ‘__main__’: main()
  • 3.  Lists – compound data type l = [1,2,3,5] # defines a list contains 1, 2, 3, 5 print l[0] # getting a value l[0] = 6 # setting a value l.append(7) # adding to list print l # will print ‘[6, 2, 3, 5, 7]’ l.extend([8, 9, 10]) # connecting another list print l # will print ‘[6, 2, 3, 5, 7, 8, 9, 10]’
  • 4. print range(3) # stops at 2 print range(1, 3) # starts at 1 and stops at 2 print range(0, 5, 2) # start: 1 stop: 4 and steps by 2
  • 5.  Create following lists with range function. 1. [0, 1, 2, 3, 4] 2. [3, 4, 5, 6, 7] 3. [3, 6, 9, 12, 15, 18] 4. [2, 4, 6, 8, 12, 16, 20] hint: use + operator
  • 6.  Answer: 1. range(5) 2. range(3, 8) 3. range(3, 21, 3) 4. range(2, 10, 2) + range(12, 24, 4)
  • 7.  Dictionaries – compound data type  Found in other languages as “map”, “associative memories”, or “associative arrays”  Lists vs Dictionaries › You can use only integer number as index on lists Like a[0], a[-1] › You can use integer numbers and strings as key on dictionaries(if its value exists) Like d[0], d[‘foo’], d[‘bar’]
  • 8.  Creating a dictionary tel = {‘John’:8000, ‘Jane’:8001, ‘Joe’:8002}  Adding key and value tel[‘Joan’] = 8003  Getting value from key tel[‘Jane’]  Setting value from key tel[‘Joe’] = 0004  Removing value from key del tel[‘John’]  Getting key list of a dictionary tel.keys()
  • 9.  Crate a dictionary from two lists names = [‘John’, ‘Jane’, ‘Joe’] tel = [8000, 8001, 8002] tel = dict(zip(names, tel))
  • 10.  Create a dictionary that › Keys are [0, 1, …, 10] › Values are (key) * 2 › i.e. d[0]=0, d[1]=2, d[2]=4, …, d[10]=20
  • 11.  Answer: k = range(11) v = range(0, 11*2, 2) d = dict(zip(k, v))
  • 12.  Logical Operator  if statements  for statements
  • 13.  Compares two values print 1 < 2 print 1 > 2 print 1 == 2 print 1 <= 2 print 1 >= 2  And, Or, and Not print 1 < 2 and 1 == 2 print 1 < 2 or 1 > 2 print not 1 == 2
  • 14. x = int(raw_input(‘value of x: ’)) if x < 0: print(‘x is negative’) # must indent elif x > 0: print(‘x is positive’) else: print(‘x is not positive neither negative’) print(‘i.e. x is zero’)
  • 15. For integer variable named ‘x’, › Print ‘fizz’ if x can be divided by 3 › Print ‘buzz’ if x can be divided by 5 (e.g. if x is 10, print ‘buzz’, x is 15, print ‘fizz buzz’) (hint: use % operator(e.g. 10 % 3 = 1, 14 % 5 = 4))
  • 16. x = int(raw_input('x value:')) if x % 3 == 0: print 'fizz' if x % 5 == 0: print 'buzz'
  • 17. n = int(raw_input(‘list length: ’)) l = [] for i in range(n): # for each number in (0…n-1) l.append(raw_input(‘%dth word: ’ % i)) for w in l: # for each word in your list print w
  • 18. Create a list only contains › Multiple of 3 or 5 (3, 5, 6, 9…) › Between 1 and 20 i.e. [3, 5, 6, 9, 10, 12, 15, 18, 20]
  • 19. l = [] for i in range(1, 21): if i % 3 == 0 or i % 5 == 0: l.append(i) print l
  • 20.  Defining a function def add(a, b): return a + b  Calling the function print add(10, 2)
  • 21.  Recursive call def factorial(n): if n <= 0: return 1 else: return n * factorial(n-1)
  • 22.  Find the 10-th Fibonacci sequence › Fibonacci sequence is  0, 1, 1, 2, 3, 5, 8, …  The next number is found by adding up the two numbers before it(e.g. 5th number 3 = 2 + 1).
  • 23. def fib(n): if n <= 1: return 0 elif n == 2: return 1 else: return fib(n-1) + fib(n-2) print fib(10)