SlideShare a Scribd company logo
1 of 19
Basic use of Python
National Institute of Technology, Anan College, JAPAN
Yoshiki Satotani
Start python interactive shell
• (Windows)
• In your explorer, to start
python shell, menu, right
click while pressing shift
key and then, press w
key. And, type python.
• (Mac or Linux)
• Just open your shell and
type python.
1. Basic operations
Basic data types (Numbers)
• Type the following commands
• 2 + 2
• 50 – 5*6
• (50 – 5.0*6) / 4
• 8 / 5.0
• 5 % 3
• 2 ** 8
• In python 2.x,
• 8 / 5 = 1
• 8.0 / 5 = 1.6 Why?
Basic data types (Strings)
• Type the following commands
• “Hello Python!”
• ‘Hello Python!’
• print ‘Hello’, ‘Python’, 2.7
• In python 3.x, print(‘Hello’, ‘Python’, 3.4)
• ‘Hello’ + ‘Python’ + str(2.7)
• Don’t do this, ‘Hello’ + ‘Python’ + 2.7
• ‘ ‘.join([‘Hello’, ‘Python’, str(2.7)])
Basic data types (Lists)
• Type the following commands
• a = [1, 2, 3, 5]
• a[0]
• a[2]
• a[-1]
• a[2:]
• a[:2]
• len(a)
• range(5)
• range(1, 5)
• range(0, 5, 2)
• # in python 3.x, [i for i in range(…)]
Basic data types (Dictionary)
• Type the following commands
• tel = {‘John’:8000, ‘Jane’:8001, ‘Joe’:8002}
• tel[‘Jane’]
• tel[‘Joan’] = 8003
• del tel[‘Jane’]
• tel.keys()
• tel.values()
• tel.items()
• names = [‘John’, ‘Jane’, ‘Joe’]
• tel = [8000, 8001, 8002]
• tel = dict(zip(names, tel))
Keyboard input
• Type the following commands
• raw_input(‘Input something: ’)
• x = int(raw_input(‘Input an integer: ‘))
• x
Function
• Type the following commands
• def Pfunc(n):
• s = 0 # 2 spaces
• for i in range(1, n+1): # 2 spaces
• s = s + I # 4 spaces
• return s # 2 spaces
• print Pfunc(10)
Summary
• Basic data types
• Numbers
• Strings
• Lists
• Dictionaries
• range() function
• Keyboard inputs
• Functions
2. Control flow statements
If, elif, else
• Type the following commands
• x = 42
• if x < 0:
• print ‘Negative’ # Insert 2 spaces in the head
• elif x == 0:
• print ‘Zero’
• else:
• print ‘Positive’
For statements
• Type the following command
• words = [‘National’, ‘United’, ‘University’, ‘Taiwan’]
• for w in words:
• print w
• for i in range(10):
• print i
List comprehension
• Type the following commands
• [4 * x for x in range(5)]
• [4 * x for x in range(5) if x % 2 == 0]
• [4 * x * y for x in range(3) for y in range(3)]
3. Graph with matplotlib
Graph of a function
• Type the following commands
• import numpy as np
• import matplotlib.pyplot as plt
• x = np.arange(-3, 3, 1.0/100)
• y = x ** 2
• plt.plot(x, y)
• plt.xlabel(r’$x$’)
• plt.ylabel(r’$y=x^{2}$’)
• plt.title(r’Graph of $y=x^{2}$’)
• plt.grid(True)
• plt.show()
Histograms
• Type the following commands
• import matplotlib.pyplot as plt
• import random
• x = [random.gauss(0, 1) for i in range(1000)]
• plt.hist(x, bins=25)
• plt.xlabel(‘Rand Norm Num’)
• plt.ylabel(‘Freq’)
• plt.title(‘Norm Dist(n=%d)’ % len(x))
• plt.show()
Pie Charts
• Type the following commands
• import matplotlib.pyplot as plt
• labels = [‘DoCoMo’, ‘au’, ‘Softbank’, ‘Emobile’, ‘Wilcom’]
• sizes = [47,27,20,2,3]
• colors = [‘red‘, ‘green’, ‘white’, ‘yellow’, ‘cyan’]
• plt.pie(sizes, labels=labels, colors=colors)
• plt.axis(‘equal’)
• plt.show()
References
• Official python tutorial
• https://docs.python.org/3.4/tutorial/
• https://docs.python.org/2/tutorial/
• Matplotlib tutorial
• http://matplotlib.org/users/pyplot_tutorial.html
• http://matplotlib.org/examples/pie_and_polar_charts/pie_demo_feat
ures.html

More Related Content

What's hot (18)

4 b file-io-if-then-else
4 b file-io-if-then-else4 b file-io-if-then-else
4 b file-io-if-then-else
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Talk Code
Talk CodeTalk Code
Talk Code
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
FSB: TreeWalker - SECCON 2015 Online CTF
FSB: TreeWalker - SECCON 2015 Online CTFFSB: TreeWalker - SECCON 2015 Online CTF
FSB: TreeWalker - SECCON 2015 Online CTF
 
Beginning Python
Beginning PythonBeginning Python
Beginning Python
 
OREO - Hack.lu CTF 2014
OREO - Hack.lu CTF 2014OREO - Hack.lu CTF 2014
OREO - Hack.lu CTF 2014
 
1 arrays and sorting
1 arrays and sorting1 arrays and sorting
1 arrays and sorting
 
Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
C arrays
C arraysC arrays
C arrays
 
Collection Core Concept
Collection Core ConceptCollection Core Concept
Collection Core Concept
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 

Viewers also liked

Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & styleKevlin Henney
 
SME Web v2.0 Primer 2011-11
SME Web v2.0 Primer 2011-11SME Web v2.0 Primer 2011-11
SME Web v2.0 Primer 2011-11Joe Katzman
 
Cincinnati Magazine - dog training feature by Lisa Desatnik
Cincinnati Magazine - dog training feature by Lisa DesatnikCincinnati Magazine - dog training feature by Lisa Desatnik
Cincinnati Magazine - dog training feature by Lisa DesatnikLisa Desatnik
 
2015 CAH Presentation copy
2015 CAH Presentation copy2015 CAH Presentation copy
2015 CAH Presentation copyDebra Kaplan
 
ใบงานสำรวจตนเอง M6
ใบงานสำรวจตนเอง M6ใบงานสำรวจตนเอง M6
ใบงานสำรวจตนเอง M6Wassana Nguytecha
 
Bab 9 diri sendiri
Bab 9 diri sendiriBab 9 diri sendiri
Bab 9 diri sendiriFirda_123
 
ใบงาน แบบสำรวจตัวเอง
ใบงาน   แบบสำรวจตัวเองใบงาน   แบบสำรวจตัวเอง
ใบงาน แบบสำรวจตัวเองnaleesaetor
 
Bring Back The Flow- Phase 3
Bring Back The Flow- Phase 3Bring Back The Flow- Phase 3
Bring Back The Flow- Phase 3robert salvit
 
Sandy's Beach Grill Slide Show
Sandy's Beach Grill Slide ShowSandy's Beach Grill Slide Show
Sandy's Beach Grill Slide ShowMarissa Spata
 
Ipa kelas 3 bab iv
Ipa kelas 3 bab ivIpa kelas 3 bab iv
Ipa kelas 3 bab ivFirda_123
 
ใบงาน แบบสำรวจคัวเอง
ใบงาน   แบบสำรวจคัวเองใบงาน   แบบสำรวจคัวเอง
ใบงาน แบบสำรวจคัวเองnaleesaetor
 
Pembangunan Ontologi dengan Development-Oriented pada Metodologi Methontology
Pembangunan Ontologi dengan Development-Oriented pada Metodologi MethontologyPembangunan Ontologi dengan Development-Oriented pada Metodologi Methontology
Pembangunan Ontologi dengan Development-Oriented pada Metodologi MethontologyMetilova Sitorus
 

Viewers also liked (15)

Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
SME Web v2.0 Primer 2011-11
SME Web v2.0 Primer 2011-11SME Web v2.0 Primer 2011-11
SME Web v2.0 Primer 2011-11
 
Cincinnati Magazine - dog training feature by Lisa Desatnik
Cincinnati Magazine - dog training feature by Lisa DesatnikCincinnati Magazine - dog training feature by Lisa Desatnik
Cincinnati Magazine - dog training feature by Lisa Desatnik
 
2015 CAH Presentation copy
2015 CAH Presentation copy2015 CAH Presentation copy
2015 CAH Presentation copy
 
Hudson Stuck
Hudson StuckHudson Stuck
Hudson Stuck
 
ใบงานสำรวจตนเอง M6
ใบงานสำรวจตนเอง M6ใบงานสำรวจตนเอง M6
ใบงานสำรวจตนเอง M6
 
Bab 9 diri sendiri
Bab 9 diri sendiriBab 9 diri sendiri
Bab 9 diri sendiri
 
ใบงาน แบบสำรวจตัวเอง
ใบงาน   แบบสำรวจตัวเองใบงาน   แบบสำรวจตัวเอง
ใบงาน แบบสำรวจตัวเอง
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
 
Pelajaran 3
Pelajaran 3Pelajaran 3
Pelajaran 3
 
Bring Back The Flow- Phase 3
Bring Back The Flow- Phase 3Bring Back The Flow- Phase 3
Bring Back The Flow- Phase 3
 
Sandy's Beach Grill Slide Show
Sandy's Beach Grill Slide ShowSandy's Beach Grill Slide Show
Sandy's Beach Grill Slide Show
 
Ipa kelas 3 bab iv
Ipa kelas 3 bab ivIpa kelas 3 bab iv
Ipa kelas 3 bab iv
 
ใบงาน แบบสำรวจคัวเอง
ใบงาน   แบบสำรวจคัวเองใบงาน   แบบสำรวจคัวเอง
ใบงาน แบบสำรวจคัวเอง
 
Pembangunan Ontologi dengan Development-Oriented pada Metodologi Methontology
Pembangunan Ontologi dengan Development-Oriented pada Metodologi MethontologyPembangunan Ontologi dengan Development-Oriented pada Metodologi Methontology
Pembangunan Ontologi dengan Development-Oriented pada Metodologi Methontology
 

Similar to Basic use of Python

Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Python programming
Python programmingPython programming
Python programmingsaroja20
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.supriyasarkar38
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.pptVicVic56
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxswarna627082
 
Session 02 python basics
Session 02 python basicsSession 02 python basics
Session 02 python basicsSara-Jayne Terp
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in pythonTMARAGATHAM
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutesSumit Raj
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha BaliAkanksha Bali
 
Python lab basics
Python lab basicsPython lab basics
Python lab basicsAbi_Kasi
 
Introduction to Python3 Programming Language
Introduction to Python3 Programming LanguageIntroduction to Python3 Programming Language
Introduction to Python3 Programming LanguageTushar Mittal
 
PyLecture1 -Python Basics-
PyLecture1 -Python Basics-PyLecture1 -Python Basics-
PyLecture1 -Python Basics-Yoshiki Satotani
 
Python tutorialfeb152012
Python tutorialfeb152012Python tutorialfeb152012
Python tutorialfeb152012Shani729
 
Python by ravi rajput hcon groups
Python by ravi rajput hcon groupsPython by ravi rajput hcon groups
Python by ravi rajput hcon groupsRavi Rajput
 

Similar to Basic use of Python (20)

Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python programming
Python programmingPython programming
Python programming
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
 
Session 02 python basics
Session 02 python basicsSession 02 python basics
Session 02 python basics
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
Python basics
Python basicsPython basics
Python basics
 
Python lab basics
Python lab basicsPython lab basics
Python lab basics
 
Python slide
Python slidePython slide
Python slide
 
Introduction to Python3 Programming Language
Introduction to Python3 Programming LanguageIntroduction to Python3 Programming Language
Introduction to Python3 Programming Language
 
First session
First sessionFirst session
First session
 
PyLecture1 -Python Basics-
PyLecture1 -Python Basics-PyLecture1 -Python Basics-
PyLecture1 -Python Basics-
 
Python tutorialfeb152012
Python tutorialfeb152012Python tutorialfeb152012
Python tutorialfeb152012
 
Python 101 1
Python 101   1Python 101   1
Python 101 1
 
Python by ravi rajput hcon groups
Python by ravi rajput hcon groupsPython by ravi rajput hcon groups
Python by ravi rajput hcon groups
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

Basic use of Python

  • 1. Basic use of Python National Institute of Technology, Anan College, JAPAN Yoshiki Satotani
  • 2. Start python interactive shell • (Windows) • In your explorer, to start python shell, menu, right click while pressing shift key and then, press w key. And, type python. • (Mac or Linux) • Just open your shell and type python.
  • 4. Basic data types (Numbers) • Type the following commands • 2 + 2 • 50 – 5*6 • (50 – 5.0*6) / 4 • 8 / 5.0 • 5 % 3 • 2 ** 8 • In python 2.x, • 8 / 5 = 1 • 8.0 / 5 = 1.6 Why?
  • 5. Basic data types (Strings) • Type the following commands • “Hello Python!” • ‘Hello Python!’ • print ‘Hello’, ‘Python’, 2.7 • In python 3.x, print(‘Hello’, ‘Python’, 3.4) • ‘Hello’ + ‘Python’ + str(2.7) • Don’t do this, ‘Hello’ + ‘Python’ + 2.7 • ‘ ‘.join([‘Hello’, ‘Python’, str(2.7)])
  • 6. Basic data types (Lists) • Type the following commands • a = [1, 2, 3, 5] • a[0] • a[2] • a[-1] • a[2:] • a[:2] • len(a) • range(5) • range(1, 5) • range(0, 5, 2) • # in python 3.x, [i for i in range(…)]
  • 7. Basic data types (Dictionary) • Type the following commands • tel = {‘John’:8000, ‘Jane’:8001, ‘Joe’:8002} • tel[‘Jane’] • tel[‘Joan’] = 8003 • del tel[‘Jane’] • tel.keys() • tel.values() • tel.items() • names = [‘John’, ‘Jane’, ‘Joe’] • tel = [8000, 8001, 8002] • tel = dict(zip(names, tel))
  • 8. Keyboard input • Type the following commands • raw_input(‘Input something: ’) • x = int(raw_input(‘Input an integer: ‘)) • x
  • 9. Function • Type the following commands • def Pfunc(n): • s = 0 # 2 spaces • for i in range(1, n+1): # 2 spaces • s = s + I # 4 spaces • return s # 2 spaces • print Pfunc(10)
  • 10. Summary • Basic data types • Numbers • Strings • Lists • Dictionaries • range() function • Keyboard inputs • Functions
  • 11. 2. Control flow statements
  • 12. If, elif, else • Type the following commands • x = 42 • if x < 0: • print ‘Negative’ # Insert 2 spaces in the head • elif x == 0: • print ‘Zero’ • else: • print ‘Positive’
  • 13. For statements • Type the following command • words = [‘National’, ‘United’, ‘University’, ‘Taiwan’] • for w in words: • print w • for i in range(10): • print i
  • 14. List comprehension • Type the following commands • [4 * x for x in range(5)] • [4 * x for x in range(5) if x % 2 == 0] • [4 * x * y for x in range(3) for y in range(3)]
  • 15. 3. Graph with matplotlib
  • 16. Graph of a function • Type the following commands • import numpy as np • import matplotlib.pyplot as plt • x = np.arange(-3, 3, 1.0/100) • y = x ** 2 • plt.plot(x, y) • plt.xlabel(r’$x$’) • plt.ylabel(r’$y=x^{2}$’) • plt.title(r’Graph of $y=x^{2}$’) • plt.grid(True) • plt.show()
  • 17. Histograms • Type the following commands • import matplotlib.pyplot as plt • import random • x = [random.gauss(0, 1) for i in range(1000)] • plt.hist(x, bins=25) • plt.xlabel(‘Rand Norm Num’) • plt.ylabel(‘Freq’) • plt.title(‘Norm Dist(n=%d)’ % len(x)) • plt.show()
  • 18. Pie Charts • Type the following commands • import matplotlib.pyplot as plt • labels = [‘DoCoMo’, ‘au’, ‘Softbank’, ‘Emobile’, ‘Wilcom’] • sizes = [47,27,20,2,3] • colors = [‘red‘, ‘green’, ‘white’, ‘yellow’, ‘cyan’] • plt.pie(sizes, labels=labels, colors=colors) • plt.axis(‘equal’) • plt.show()
  • 19. References • Official python tutorial • https://docs.python.org/3.4/tutorial/ • https://docs.python.org/2/tutorial/ • Matplotlib tutorial • http://matplotlib.org/users/pyplot_tutorial.html • http://matplotlib.org/examples/pie_and_polar_charts/pie_demo_feat ures.html