SlideShare a Scribd company logo
1 of 31
Download to read offline
@DylanSeychell
Introduction to Python
Dylan Seychell
@DylanSeychell
What is Python?
● Widely used and supported
● Interpreted Scripting Language
● Focuses on Readability and Productivity
● Multipurpose:
○ Web Programming
○ GUI Applications
○ Computer Vision Apps
○ Data Science
○ And much more…
○ But no, not yet adequate for mobile programming :(
2
@DylanSeychell
Installing Python
● Python can be downloaded from the official site:
https://www.python.org/downloads/
○ Further libraries would need to be configured manually.
● You may also download Python from the Anaconda platform through this link:
https://www.anaconda.com/download/
○ This approach facilitates the management of different environments and its benefits would be
more tangible at a later stage.
3
@DylanSeychell
Getting started with syntax, in shell
4
@DylanSeychell
Using Python from the interactive shell
From your Terminal/CMD, type ‘python’ to get started
Dylans-MacBook-Pro-3:~ dylanseychell$ python
A successful configuration will return something like the following:
Python 2.7.13 |Anaconda custom (x86_64)| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>>
You may now use Python shell by typing commands after the >>>
To quit Python in terminal, simply type exit()
5
@DylanSeychell
Calculations
Once running Python from shell, you may execute some commands as follows:
Calculations:
>>> 6+3
9
Or even…
>>> (7*2)+11-(4/2)
23
6
@DylanSeychell
Comparisons
Python can processes logical/comparison operations and return a Boolean result
accordingly:
>>> 3>4
False
>>> 2==2
True
>>> 3!=1
True
>>> 3 < (15/3)
True
>>> 4 > (3*3)
False
7
@DylanSeychell
Declaring Variables
Variables are declared by simply naming them and assigning an initial value. The
variable type is not declared.
Declaring a variable does not return specific feedback.
>>> a = 3
>>>
You may however check the content of the variable by calling it after declaration.
>>> a
3
8
@DylanSeychell
Using Variables to store numbers
Variables and mathematical operations
>>> a = 3
>>> a + 1
4
Values would be updated accordingly and they can be reused.
>>> a * 2
8
9
@DylanSeychell
Variables and Strings
Text is stored in the same way
>>> s = "hello"
>>> s
'hello'
It’s also easy to concatenate text by using the + operator
>>> s + " world"
'hello world'
Or maybe, replicate for defined number of times by using the * operator
>>> s*3
'hellohellohello'
10
@DylanSeychell
Comments:
Comments in Python
are triggered by the
symbol #
11
#
@DylanSeychell
Functions on Strings
You may need to check the length of a string (or object). Just use len()
>>> len (s) #s still contains ‘hello’
5
Or convert to upper or lower case
>>> s.upper()
'HELLO'
>>> s.lower()
'Hello'
12
@DylanSeychell
Accessing characters in Strings
Index of characters starts from zero (left) incrementing towards the right
Characters may also be accessed by their distance from the end, this time -1 means
the first from the end (can’t have -0).
13
@DylanSeychell
Accessing characters in a String (examples)
Characters can be accessed by the use of [] like most other popular languages.
>>> s[0]
'h'
>>> s[3]
'l'
They can also be accessed with reference to their position from the end of the
string.
>>> s[-5]
'h'
>>> s[-1]
'o'
14
@DylanSeychell
Slicing Strings
Strings can be sliced by using the s[start:end] notation. This allows us to
extract a substring that falls within the specified range. End is not included.
>>> s[1:3]
'el'
>>> s[3:4]
'l'
>>> s[1:4]
'ell'
If the end index is greater than the length, the result is truncated.
>>> s[1:100]
'ello'
15
@DylanSeychell
Using Python from an editor
16
@DylanSeychell
Using Python from an editor
The approach to write more complex Python code
requires you to write code in a file.
Python module files must have a .py suffix
These can be written through any text editing
software.
I personally prefer Atom (http://atom.io) particularly
because you can also have a terminal screen as
part of the editor and install a nice variety of plugins.
To execute a script, find the designated folder from
the terminal and type python scriptName.py
17
@DylanSeychell
Code Blocks:
Python does not use
{ and } to establish
code blocks. It uses
tabs instead. 18
{
}
@DylanSeychell
Functions
Functions in Python are defined by writing the keyword def followed by the name
of the function and parameters. This has to be followed by a colon : and the
code-block has to be tabbed.
def show(a):
print(a)
This is then simply called anywhere else in the module.
show(“hello”) #prints “hello” to console
19
@DylanSeychell
Round Brackets:
Round brackets ( ) are not
required when testing
conditions. You may still
use them though :)
20
(
)
@DylanSeychell
IF Statements
Based on the same concept traditional programming languages where a
code-block is executed when the testing condition is true.
a = 3
if a > 2:
print ("a is > than 2")
Notes:
1) That the testing condition did not need to be surrounded by round brackets
2) The code block is established by a colon : after the testing condition and the
statements were then indented by a tab.
21
@DylanSeychell
ELIF (else-if) and ELSE
The elif statement is used to to cover other logical testing conditions.
a = 3
if a > 2:
print ("a is > than 2")
elif a < 2:
print ("a is < than 2")
The else statement is used to cover all other possibilities.
else:
print ("a is equal to 2")
22
@DylanSeychell
Comparison Operators
Python uses the commonly used C-style comparison operators
● <
● >
● <=
● >=
● !=
● ==
23
@DylanSeychell
Logical Operators
Python does not use the C-style logical operators (&&, || and !)
The keywords and, or and not are used instead.
if a > 2 and a < 4:
print ("a must be 3")
24
@DylanSeychell
Lists
One of Python’s built-in features and can be initialised by []
months = []
List literals are stored in square brackets []
months = ['March', 'May', 'September']
print (months)
Items may be accessed by their index.
print (months[1]) ##returns May
25
@DylanSeychell
Adding items to lists
The append method allows us to add new items to a list.
months.append("December")
The insert method allows us to add new items to a list at a specific index
months.insert(0, "January")
26
@DylanSeychell
Methods on lists
The length of the list may be checked by using len
print (len(months)) #returns 3
Lists may be reversed by the calling the reverse function (does not return)
months.reverse()
print (months) ## returns ['September', 'May', 'March']
27
@DylanSeychell
FOR construct
The for construct is used in Python to iterate through lists or other structures. This
uses a var in list pattern, where the var would be an iterator of the same type of
the list.
months = ['March', 'May', 'September']
for month in months:
print (month)
The above prints the contents of this list.
28
@DylanSeychell
IN Construct
The in construct can also be used to to test whether an element exists in a list.
if 'May' in months:
print ("I know about this month!")
29
@DylanSeychell
Using FOR to generate numbers
The FOR construct can be used like the for in C-style languages.
for i in range(4):
print (i)
The range generates numbers from 0 up until the number passed as a parameter
and not including this last number.
Range can also accept a start and end parameter as follows: range(2,4)
30
@DylanSeychell
Need more assistance?
Let’s get in touch.
31

More Related Content

What's hot (20)

Namespace--defining same identifiers again
Namespace--defining same identifiers againNamespace--defining same identifiers again
Namespace--defining same identifiers again
 
Introduction to PythonTeX
Introduction to PythonTeXIntroduction to PythonTeX
Introduction to PythonTeX
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Systemcall
SystemcallSystemcall
Systemcall
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
New features in Ruby 2.4
New features in Ruby 2.4New features in Ruby 2.4
New features in Ruby 2.4
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
linked list
linked list linked list
linked list
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
python-message-0.1.0
python-message-0.1.0python-message-0.1.0
python-message-0.1.0
 
ch 2. Python module
ch 2. Python module ch 2. Python module
ch 2. Python module
 
Fundamental
FundamentalFundamental
Fundamental
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
2014 Taverna tutorial Tool service
2014 Taverna tutorial Tool service2014 Taverna tutorial Tool service
2014 Taverna tutorial Tool service
 
Lecture2
Lecture2Lecture2
Lecture2
 
Lecture3
Lecture3Lecture3
Lecture3
 
ADot netme assignment
ADot netme assignmentADot netme assignment
ADot netme assignment
 
Lecture4
Lecture4Lecture4
Lecture4
 
Link list part 1
Link list part 1Link list part 1
Link list part 1
 
Call Execute For Everyone
Call Execute For EveryoneCall Execute For Everyone
Call Execute For Everyone
 

Similar to Introduction to Python

علم البيانات - Data Sience
علم البيانات - Data Sience علم البيانات - Data Sience
علم البيانات - Data Sience App Ttrainers .com
 
The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210Mahmoud Samir Fayed
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptxNileshBorkar12
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfSudhanshiBakre1
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxadihartanto7
 
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
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202Mahmoud Samir Fayed
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.pptbalewayalew
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizeIruolagbePius
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxusvirat1805
 
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAaravNayan
 

Similar to Introduction to Python (20)

Python basics
Python basicsPython basics
Python basics
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
علم البيانات - Data Sience
علم البيانات - Data Sience علم البيانات - Data Sience
علم البيانات - Data Sience
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.9 book - Part 7 of 210
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdf
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 
Python for web security - beginner
Python for web security - beginnerPython for web security - beginner
Python for web security - beginner
 
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...
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
 
Python1
Python1Python1
Python1
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
 
Python Session - 2
Python Session - 2Python Session - 2
Python Session - 2
 
PYTHON 101.pptx
PYTHON 101.pptxPYTHON 101.pptx
PYTHON 101.pptx
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
 

Recently uploaded

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Recently uploaded (20)

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

Introduction to Python

  • 2. @DylanSeychell What is Python? ● Widely used and supported ● Interpreted Scripting Language ● Focuses on Readability and Productivity ● Multipurpose: ○ Web Programming ○ GUI Applications ○ Computer Vision Apps ○ Data Science ○ And much more… ○ But no, not yet adequate for mobile programming :( 2
  • 3. @DylanSeychell Installing Python ● Python can be downloaded from the official site: https://www.python.org/downloads/ ○ Further libraries would need to be configured manually. ● You may also download Python from the Anaconda platform through this link: https://www.anaconda.com/download/ ○ This approach facilitates the management of different environments and its benefits would be more tangible at a later stage. 3
  • 5. @DylanSeychell Using Python from the interactive shell From your Terminal/CMD, type ‘python’ to get started Dylans-MacBook-Pro-3:~ dylanseychell$ python A successful configuration will return something like the following: Python 2.7.13 |Anaconda custom (x86_64)| (default, Dec 20 2016, 23:05:08) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org >>> You may now use Python shell by typing commands after the >>> To quit Python in terminal, simply type exit() 5
  • 6. @DylanSeychell Calculations Once running Python from shell, you may execute some commands as follows: Calculations: >>> 6+3 9 Or even… >>> (7*2)+11-(4/2) 23 6
  • 7. @DylanSeychell Comparisons Python can processes logical/comparison operations and return a Boolean result accordingly: >>> 3>4 False >>> 2==2 True >>> 3!=1 True >>> 3 < (15/3) True >>> 4 > (3*3) False 7
  • 8. @DylanSeychell Declaring Variables Variables are declared by simply naming them and assigning an initial value. The variable type is not declared. Declaring a variable does not return specific feedback. >>> a = 3 >>> You may however check the content of the variable by calling it after declaration. >>> a 3 8
  • 9. @DylanSeychell Using Variables to store numbers Variables and mathematical operations >>> a = 3 >>> a + 1 4 Values would be updated accordingly and they can be reused. >>> a * 2 8 9
  • 10. @DylanSeychell Variables and Strings Text is stored in the same way >>> s = "hello" >>> s 'hello' It’s also easy to concatenate text by using the + operator >>> s + " world" 'hello world' Or maybe, replicate for defined number of times by using the * operator >>> s*3 'hellohellohello' 10
  • 11. @DylanSeychell Comments: Comments in Python are triggered by the symbol # 11 #
  • 12. @DylanSeychell Functions on Strings You may need to check the length of a string (or object). Just use len() >>> len (s) #s still contains ‘hello’ 5 Or convert to upper or lower case >>> s.upper() 'HELLO' >>> s.lower() 'Hello' 12
  • 13. @DylanSeychell Accessing characters in Strings Index of characters starts from zero (left) incrementing towards the right Characters may also be accessed by their distance from the end, this time -1 means the first from the end (can’t have -0). 13
  • 14. @DylanSeychell Accessing characters in a String (examples) Characters can be accessed by the use of [] like most other popular languages. >>> s[0] 'h' >>> s[3] 'l' They can also be accessed with reference to their position from the end of the string. >>> s[-5] 'h' >>> s[-1] 'o' 14
  • 15. @DylanSeychell Slicing Strings Strings can be sliced by using the s[start:end] notation. This allows us to extract a substring that falls within the specified range. End is not included. >>> s[1:3] 'el' >>> s[3:4] 'l' >>> s[1:4] 'ell' If the end index is greater than the length, the result is truncated. >>> s[1:100] 'ello' 15
  • 17. @DylanSeychell Using Python from an editor The approach to write more complex Python code requires you to write code in a file. Python module files must have a .py suffix These can be written through any text editing software. I personally prefer Atom (http://atom.io) particularly because you can also have a terminal screen as part of the editor and install a nice variety of plugins. To execute a script, find the designated folder from the terminal and type python scriptName.py 17
  • 18. @DylanSeychell Code Blocks: Python does not use { and } to establish code blocks. It uses tabs instead. 18 { }
  • 19. @DylanSeychell Functions Functions in Python are defined by writing the keyword def followed by the name of the function and parameters. This has to be followed by a colon : and the code-block has to be tabbed. def show(a): print(a) This is then simply called anywhere else in the module. show(“hello”) #prints “hello” to console 19
  • 20. @DylanSeychell Round Brackets: Round brackets ( ) are not required when testing conditions. You may still use them though :) 20 ( )
  • 21. @DylanSeychell IF Statements Based on the same concept traditional programming languages where a code-block is executed when the testing condition is true. a = 3 if a > 2: print ("a is > than 2") Notes: 1) That the testing condition did not need to be surrounded by round brackets 2) The code block is established by a colon : after the testing condition and the statements were then indented by a tab. 21
  • 22. @DylanSeychell ELIF (else-if) and ELSE The elif statement is used to to cover other logical testing conditions. a = 3 if a > 2: print ("a is > than 2") elif a < 2: print ("a is < than 2") The else statement is used to cover all other possibilities. else: print ("a is equal to 2") 22
  • 23. @DylanSeychell Comparison Operators Python uses the commonly used C-style comparison operators ● < ● > ● <= ● >= ● != ● == 23
  • 24. @DylanSeychell Logical Operators Python does not use the C-style logical operators (&&, || and !) The keywords and, or and not are used instead. if a > 2 and a < 4: print ("a must be 3") 24
  • 25. @DylanSeychell Lists One of Python’s built-in features and can be initialised by [] months = [] List literals are stored in square brackets [] months = ['March', 'May', 'September'] print (months) Items may be accessed by their index. print (months[1]) ##returns May 25
  • 26. @DylanSeychell Adding items to lists The append method allows us to add new items to a list. months.append("December") The insert method allows us to add new items to a list at a specific index months.insert(0, "January") 26
  • 27. @DylanSeychell Methods on lists The length of the list may be checked by using len print (len(months)) #returns 3 Lists may be reversed by the calling the reverse function (does not return) months.reverse() print (months) ## returns ['September', 'May', 'March'] 27
  • 28. @DylanSeychell FOR construct The for construct is used in Python to iterate through lists or other structures. This uses a var in list pattern, where the var would be an iterator of the same type of the list. months = ['March', 'May', 'September'] for month in months: print (month) The above prints the contents of this list. 28
  • 29. @DylanSeychell IN Construct The in construct can also be used to to test whether an element exists in a list. if 'May' in months: print ("I know about this month!") 29
  • 30. @DylanSeychell Using FOR to generate numbers The FOR construct can be used like the for in C-style languages. for i in range(4): print (i) The range generates numbers from 0 up until the number passed as a parameter and not including this last number. Range can also accept a start and end parameter as follows: range(2,4) 30