SlideShare a Scribd company logo
PyLecture1 -Python Basics-
 Installation
 Create easy networks and show them
 The interactive shell vs scripts
› Running the interactive shell
 just type ‘python’
› Running a script
 type ‘python <script-name>’ (e.g. python
script.py)
 Numbers
>>> 2 + 2
4
>>> 50 - 5*6
20
>>> (50 - 5.0*6) / 4
5.0
>>> 8 / 5.0
1.6
>>> 5 % 3
2
>>> 2 ** 8
256
› int – the integer values(2, 7, 20…)
› float – the ones with a fractional part(1.0, 3.14…)
› int / int -> int (5 / 3 = 1, not 1.66…)
› int / float -> float, float / int -> float
 Strings
› Can be enclosed in single quotes (i.e. ‘…’) or
double quotes (i.e. “…”)
>>> “Hello Python!”
‘Hello Python!’
>>> print “Hello”, “Python”, 2.7
Hello Python 2.7
 Lists – compound data type
>>> [1,2,3,5][0]
1
>>> [1,2,3,5][2]
3
>>> [1,2,3,5][-1]
5
>>> [1,2,3,5][2:]
[3, 5]
>>> [1,2,3,5][:2]
[1, 2]
>>> len([1,2,3,5])
4
>>> range(4)
[0,1,2,3] (Creates a 4-value list starts with 0)
 The equal sign(=) is used to assign a
value to a variable
>>> width = 5
>>> height = 10
>>> print ‘Triangle area:’, (width * height / 2.0)
Triangle area: 25.0
>>> raw_input(‘Please enter something: ’)
Please enter something: <your response>
‘<your response>’ – string type!
>>> x = int(raw_input(‘Enter an integer: ‘))
Enter an integer: -1
>>> x
-1
 Two methods
› the interactive shell
› scripts
 Basic data types
› Numbers
› Strings
› Lists
 range() function
 Variable
 Inputs from your keyboard
 if, elif, else statements
>>> x = 42
>>> if x < 0:
… print ‘Negative’
…elif x == 0:
… print ‘Zero’
…else:
… print ‘Positive’
…
Positive
 You can skip elif and/or else.
>>> if x < 0:
… print ‘Negative’
… else:
… print ‘Not negative’
…
Not negative
>>> if x > 0:
… print ‘Positive’
…
Positive
 for statements
>>> words = [‘Mac’, ‘Linux’, ‘Windows’]
>>> for w in words:
… print w
…
Mac
Linux
Windows
>>>
>>> for i in range(len(words)):
… print words[i]
…
 Generates a list with for statement(s)
>>> [4 * x for x in range(5)]
[0, 4, 8, 12, 16]
>>> [4 * x for x in range(5) if x % 2 == 0]
[0, 8, 16]
>>> [4*x*y for x in range(1,3) for y in range(1,3)]
[4, 8, 8, 16]
 Control flow statements
› if statements
› for statements
 List comprehension

More Related Content

What's hot (20)

Database design and error handling
Database design and error handlingDatabase design and error handling
Database design and error handling
hamsa nandhini
 
Introduction to MySQL in PHP
Introduction to MySQL in PHPIntroduction to MySQL in PHP
Introduction to MySQL in PHP
hamsa nandhini
 
Eureka - elegant iOs form builder in swift (johnp - mingle)
Eureka - elegant iOs form builder in swift (johnp - mingle)Eureka - elegant iOs form builder in swift (johnp - mingle)
Eureka - elegant iOs form builder in swift (johnp - mingle)
John Pham
 
Ruby 2: some new things
Ruby 2: some new thingsRuby 2: some new things
Ruby 2: some new things
David Black
 
How to get help in R?
How to get help in R?How to get help in R?
How to get help in R?
Rsquared Academy
 
Basics of PHP
Basics of PHPBasics of PHP
Basics of PHP
hamsa nandhini
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
Bardia Heydari
 
Python basics
Python basicsPython basics
Python basics
NexThoughts Technologies
 
Types my way: Static Typing in Python
Types my way: Static Typing in PythonTypes my way: Static Typing in Python
Types my way: Static Typing in Python
Joe Cabrera
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 
Hacking XPATH 2.0
Hacking XPATH 2.0Hacking XPATH 2.0
Hacking XPATH 2.0
michelemanzotti
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath Injections
AMol NAik
 
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
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Sayed Ahmed
 
David Grudl: Novinky v Nette
David Grudl: Novinky v NetteDavid Grudl: Novinky v Nette
David Grudl: Novinky v Nette
Develcz
 
Xpath injection in XML databases
Xpath injection in XML databasesXpath injection in XML databases
Xpath injection in XML databases
Triad Square InfoSec
 
Internal DSLs Scala
Internal DSLs ScalaInternal DSLs Scala
Internal DSLs Scala
zefhemel
 
Control de acceso con excel
Control de acceso con excelControl de acceso con excel
Control de acceso con excel
Reember Alex Arteaga Ticona
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعةشرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
جامعة القدس المفتوحة
 
Uniface Lectures Webinar - Uniface 10 Technical Deep Dive
Uniface Lectures Webinar - Uniface 10 Technical Deep DiveUniface Lectures Webinar - Uniface 10 Technical Deep Dive
Uniface Lectures Webinar - Uniface 10 Technical Deep Dive
Uniface
 
Database design and error handling
Database design and error handlingDatabase design and error handling
Database design and error handling
hamsa nandhini
 
Introduction to MySQL in PHP
Introduction to MySQL in PHPIntroduction to MySQL in PHP
Introduction to MySQL in PHP
hamsa nandhini
 
Eureka - elegant iOs form builder in swift (johnp - mingle)
Eureka - elegant iOs form builder in swift (johnp - mingle)Eureka - elegant iOs form builder in swift (johnp - mingle)
Eureka - elegant iOs form builder in swift (johnp - mingle)
John Pham
 
Ruby 2: some new things
Ruby 2: some new thingsRuby 2: some new things
Ruby 2: some new things
David Black
 
Types my way: Static Typing in Python
Types my way: Static Typing in PythonTypes my way: Static Typing in Python
Types my way: Static Typing in Python
Joe Cabrera
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath Injections
AMol NAik
 
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
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Sayed Ahmed
 
David Grudl: Novinky v Nette
David Grudl: Novinky v NetteDavid Grudl: Novinky v Nette
David Grudl: Novinky v Nette
Develcz
 
Internal DSLs Scala
Internal DSLs ScalaInternal DSLs Scala
Internal DSLs Scala
zefhemel
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعةشرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
جامعة القدس المفتوحة
 
Uniface Lectures Webinar - Uniface 10 Technical Deep Dive
Uniface Lectures Webinar - Uniface 10 Technical Deep DiveUniface Lectures Webinar - Uniface 10 Technical Deep Dive
Uniface Lectures Webinar - Uniface 10 Technical Deep Dive
Uniface
 

Viewers also liked (8)

งานคู่
งานคู่งานคู่
งานคู่
naleesaetor
 
Surya univ arduino-muhammad-bangun--agung-202136575862733
Surya univ arduino-muhammad-bangun--agung-202136575862733Surya univ arduino-muhammad-bangun--agung-202136575862733
Surya univ arduino-muhammad-bangun--agung-202136575862733
Alqharomi
 
Top 8 stationary engineer resume samples
Top 8 stationary engineer resume samplesTop 8 stationary engineer resume samples
Top 8 stationary engineer resume samples
tonychoper2105
 
How to get the best from your CFO
How to get the best from your CFOHow to get the best from your CFO
How to get the best from your CFO
MyCFO Services
 
Tata steel &amp; sail
Tata steel &amp; sailTata steel &amp; sail
Tata steel &amp; sail
Institute Of Professional Education And Research
 
lettera al mercato IVASS Banca polizze abbinate a finanziamenti
lettera al mercato IVASS Banca polizze abbinate a finanziamentilettera al mercato IVASS Banca polizze abbinate a finanziamenti
lettera al mercato IVASS Banca polizze abbinate a finanziamenti
Salvatore Iannitti
 
CRIMEN Y CASTIGO
CRIMEN Y CASTIGOCRIMEN Y CASTIGO
CRIMEN Y CASTIGO
Tatiana Rodriguez Olarte
 
Presentacion herramientas
Presentacion herramientasPresentacion herramientas
Presentacion herramientas
leiramirez
 
งานคู่
งานคู่งานคู่
งานคู่
naleesaetor
 
Surya univ arduino-muhammad-bangun--agung-202136575862733
Surya univ arduino-muhammad-bangun--agung-202136575862733Surya univ arduino-muhammad-bangun--agung-202136575862733
Surya univ arduino-muhammad-bangun--agung-202136575862733
Alqharomi
 
Top 8 stationary engineer resume samples
Top 8 stationary engineer resume samplesTop 8 stationary engineer resume samples
Top 8 stationary engineer resume samples
tonychoper2105
 
How to get the best from your CFO
How to get the best from your CFOHow to get the best from your CFO
How to get the best from your CFO
MyCFO Services
 
lettera al mercato IVASS Banca polizze abbinate a finanziamenti
lettera al mercato IVASS Banca polizze abbinate a finanziamentilettera al mercato IVASS Banca polizze abbinate a finanziamenti
lettera al mercato IVASS Banca polizze abbinate a finanziamenti
Salvatore Iannitti
 
Presentacion herramientas
Presentacion herramientasPresentacion herramientas
Presentacion herramientas
leiramirez
 
Ad

Similar to PyLecture1 -Python Basics- (20)

Basic use of Python
Basic use of PythonBasic use of Python
Basic use of Python
Yoshiki Satotani
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
Larry Cai
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
Andrew McNicol
 
Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3
FabMinds
 
Python
PythonPython
Python
Gagandeep Nanda
 
Practical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptxPractical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptx
trwdcn
 
PYTHON
PYTHONPYTHON
PYTHON
JOHNYAMSON
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Dr.C S Prasanth-Physics ppt.pptx computer
Dr.C S Prasanth-Physics ppt.pptx computerDr.C S Prasanth-Physics ppt.pptx computer
Dr.C S Prasanth-Physics ppt.pptx computer
kavitamittal18
 
Computer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
RedenOriola
 
Python tutorialfeb152012
Python tutorialfeb152012Python tutorialfeb152012
Python tutorialfeb152012
Shani729
 
IoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptxIoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptx
afsheenfaiq2
 
Python: An introduction A summer workshop
Python: An  introduction A summer workshopPython: An  introduction A summer workshop
Python: An introduction A summer workshop
ForrayFerenc
 
python1.pptpppppppppppppppppppppppppppppppp
python1.pptpppppppppppppppppppppppppppppppppython1.pptpppppppppppppppppppppppppppppppp
python1.pptpppppppppppppppppppppppppppppppp
divijareddy0502
 
Learn Python in three hours - Python is an experiment
Learn Python in three hours - Python is an experimentLearn Python in three hours - Python is an experiment
Learn Python in three hours - Python is an experiment
Anil Yadav
 
python programing 101 presentation ... Let's start
python programing 101 presentation ... Let's startpython programing 101 presentation ... Let's start
python programing 101 presentation ... Let's start
Mohsen Hefni
 
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.pptpythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
HamidKhemili
 
uso del lenguaje de programación python en métodos numéricos..ppt
uso del lenguaje de programación python en métodos numéricos..pptuso del lenguaje de programación python en métodos numéricos..ppt
uso del lenguaje de programación python en métodos numéricos..ppt
angelca13
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
Larry Cai
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
Andrew McNicol
 
Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3
FabMinds
 
Practical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptxPractical Python.pptx Practical Python.pptx
Practical Python.pptx Practical Python.pptx
trwdcn
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Dr.C S Prasanth-Physics ppt.pptx computer
Dr.C S Prasanth-Physics ppt.pptx computerDr.C S Prasanth-Physics ppt.pptx computer
Dr.C S Prasanth-Physics ppt.pptx computer
kavitamittal18
 
Computer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
RedenOriola
 
Python tutorialfeb152012
Python tutorialfeb152012Python tutorialfeb152012
Python tutorialfeb152012
Shani729
 
IoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptxIoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptx
afsheenfaiq2
 
Python: An introduction A summer workshop
Python: An  introduction A summer workshopPython: An  introduction A summer workshop
Python: An introduction A summer workshop
ForrayFerenc
 
python1.pptpppppppppppppppppppppppppppppppp
python1.pptpppppppppppppppppppppppppppppppppython1.pptpppppppppppppppppppppppppppppppp
python1.pptpppppppppppppppppppppppppppppppp
divijareddy0502
 
Learn Python in three hours - Python is an experiment
Learn Python in three hours - Python is an experimentLearn Python in three hours - Python is an experiment
Learn Python in three hours - Python is an experiment
Anil Yadav
 
python programing 101 presentation ... Let's start
python programing 101 presentation ... Let's startpython programing 101 presentation ... Let's start
python programing 101 presentation ... Let's start
Mohsen Hefni
 
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.pptpythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
pythegggggeeeeeeeeeeeeeeeeeeeeeeeon1.ppt
HamidKhemili
 
uso del lenguaje de programación python en métodos numéricos..ppt
uso del lenguaje de programación python en métodos numéricos..pptuso del lenguaje de programación python en métodos numéricos..ppt
uso del lenguaje de programación python en métodos numéricos..ppt
angelca13
 
Ad

More from Yoshiki Satotani (6)

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
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
Yoshiki Satotani
 
PyLecture4 -Python Basics2-
PyLecture4 -Python Basics2-PyLecture4 -Python Basics2-
PyLecture4 -Python Basics2-
Yoshiki Satotani
 
PyLecture2 -NetworkX-
PyLecture2 -NetworkX-PyLecture2 -NetworkX-
PyLecture2 -NetworkX-
Yoshiki Satotani
 
PyLecture3 -json-
PyLecture3 -json-PyLecture3 -json-
PyLecture3 -json-
Yoshiki Satotani
 

PyLecture1 -Python Basics-

  • 2.  Installation  Create easy networks and show them
  • 3.  The interactive shell vs scripts › Running the interactive shell  just type ‘python’ › Running a script  type ‘python <script-name>’ (e.g. python script.py)
  • 4.  Numbers >>> 2 + 2 4 >>> 50 - 5*6 20 >>> (50 - 5.0*6) / 4 5.0 >>> 8 / 5.0 1.6 >>> 5 % 3 2 >>> 2 ** 8 256 › int – the integer values(2, 7, 20…) › float – the ones with a fractional part(1.0, 3.14…) › int / int -> int (5 / 3 = 1, not 1.66…) › int / float -> float, float / int -> float
  • 5.  Strings › Can be enclosed in single quotes (i.e. ‘…’) or double quotes (i.e. “…”) >>> “Hello Python!” ‘Hello Python!’ >>> print “Hello”, “Python”, 2.7 Hello Python 2.7
  • 6.  Lists – compound data type >>> [1,2,3,5][0] 1 >>> [1,2,3,5][2] 3 >>> [1,2,3,5][-1] 5 >>> [1,2,3,5][2:] [3, 5] >>> [1,2,3,5][:2] [1, 2] >>> len([1,2,3,5]) 4 >>> range(4) [0,1,2,3] (Creates a 4-value list starts with 0)
  • 7.  The equal sign(=) is used to assign a value to a variable >>> width = 5 >>> height = 10 >>> print ‘Triangle area:’, (width * height / 2.0) Triangle area: 25.0
  • 8. >>> raw_input(‘Please enter something: ’) Please enter something: <your response> ‘<your response>’ – string type! >>> x = int(raw_input(‘Enter an integer: ‘)) Enter an integer: -1 >>> x -1
  • 9.  Two methods › the interactive shell › scripts  Basic data types › Numbers › Strings › Lists  range() function  Variable  Inputs from your keyboard
  • 10.  if, elif, else statements >>> x = 42 >>> if x < 0: … print ‘Negative’ …elif x == 0: … print ‘Zero’ …else: … print ‘Positive’ … Positive
  • 11.  You can skip elif and/or else. >>> if x < 0: … print ‘Negative’ … else: … print ‘Not negative’ … Not negative >>> if x > 0: … print ‘Positive’ … Positive
  • 12.  for statements >>> words = [‘Mac’, ‘Linux’, ‘Windows’] >>> for w in words: … print w … Mac Linux Windows >>> >>> for i in range(len(words)): … print words[i] …
  • 13.  Generates a list with for statement(s) >>> [4 * x for x in range(5)] [0, 4, 8, 12, 16] >>> [4 * x for x in range(5) if x % 2 == 0] [0, 8, 16] >>> [4*x*y for x in range(1,3) for y in range(1,3)] [4, 8, 8, 16]
  • 14.  Control flow statements › if statements › for statements  List comprehension