SlideShare a Scribd company logo
1 of 37
Download to read offline
Introduction to Python

a readable, dynamic, pleasant, 

flexible, fast and powerful language.
Murtadha Bazli Tukimat

Developer/Founder at Wekanta

bazli@wekanta.com
Wekanta
Overview
๏ Background
๏ Syntax
๏ Variables
๏ Data Structure
๏ Comparison
๏ Control Flow
๏ Function
Wekanta
What is Python?
• Python is a dynamic, interpreted (bytecode-compiled) and
multi-platform language

• No type declarations of variables, parameters, functions,
or methods in source code

• Code become short and fast to compile
Wekanta
Why Python?
• Machine learning, NLP and data scientific tools packages

• From embedded system to the web applications

(Web, GUI, Scripting, etc.)

• A general purpose language



Read it more → https://goo.gl/ZwtjJV
Wekanta
Syntax
๏ Hello World!
๏ Indentation
๏ Naming Convention
๏ Comment
Wekanta
#!/usr/local/bin/python3

print(“hello world!”)
Hello World!
Wekanta
• Indentation affects code's meaning

• End of the line means end of the statement

• Inconsistent indentation == Syntax Error

• Tabs vs Spaces?

Spaces are the preferred indentation method.
Indentation
Wekanta
Indentation Cont'd
If foo:

If bar:

print('Hello World')
else:

print('Welcome to Python')
Wekanta
• b (single lowercase)
• B (single uppercase)

• lowercase
• lower_case_underscore
• UPPERCASE

• UPPER_CASE_UNDERSCORE

• CamelCase
• mixedCase

• Camel_Case_Underscore (ugly)
Naming Convention
Wekanta
# This is single line comment

' This is also single line comment '

' This is a single line comment too '

'''

This is example of

multi-line comment.

'''
Comment
Wekanta
Variables
๏ String
๏ Number
๏ Boolean
๏ Null
Wekanta
String
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# declaration

s = 'hello python'



# methods

s.lower() # return string lowercase version

s.upper() # return string uppercase version

s.strip() # remove trailing & leading whitespaces

s.isalpha() # alphanumeric test

s.isdigit() # digit/number test

s.isspace() # spaces test

s.startswith('hello') # check if string start with 'foo'

s.endswith('python') # check if string ending with 'bar'

s.find('hello') # return 'foo' index

s.replace('hello', 'hi') # replace 'foo' with 'bar' string

s.split('hello') # return list of substrings

s.join(list) # opposite of split
Wekanta
String Cont'd
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

s = 'Hello, this is Python '



s.lower() # 'hello, this is python '

s.upper() # 'HELLO, THIS IS PYTHON '

s.strip() # 'Hello, this is Python'

s.lower().find('hello') # 0

s.replace('this', 'that') # 'Hello, that is Python '

s = s.split(',') # ['Hello', ' this is Python ']

','.join(s) # 'Hello, this is Python '
Wekanta
Number
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# integer number

year = 2010

year = int('2010')

# floating point number

temperature = 27.6

temperature = float('27.6')

# fixed point number

price = Decimal('12.50')
Wekanta
Boolean
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

is_python = True

# cast to any variables

is_python = bool(0)

is_python = bool('check')
Wekanta
Null
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
optional_data = None
Wekanta
Data Structure
๏ List
๏ Dictionary
Wekanta
List
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# declaration

list = []

list = list()

# methods

list.append(element)

list.extend(list2)

list.insert(index, element)

list.remove(element)

list.pop(index)

list.clear()

list.index(element)

list.count(element)

list.sort()

list.reverse()

list.copy()
Wekanta
List Cont'd
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

list = ['bazli', 'hidayah', 'nabila']



list.append('others')         # append 'others' at end

list.extend(['yyy', 'zzz'])   # add list of element at end

list.insert(0, 'xxx')         # insert 'xxx' at index 0
print(list)

# ['xxx', 'bazli', 'hidayah', 'nabila', 'others', 'yyy', 'zzz']



print(list.index('bazli'))    # 1

list.remove('bazli')         # search and remove that element

list.pop(1)                   # removes and returns 'larry'
print(list.count('xxx')) # 1

print(list)

# ['xxx', 'nabila', 'others', 'yyy', 'zzz']

Wekanta
List Slices
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

list = ['a', 'b', 'c', 'd']



print(list[1:-1])  # ['b', 'c']

print(list[:-1])   # ['a', 'b', 'c']



list[0:2] = 'z'    # replace ['a', 'b'] with 'z'



print(list)        # ['z', 'c', 'd']
Wekanta
Dictionary
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# declaration

dict = {}

dict = dict()



# methods

dict.clear()

dict.copy()

dict.get()

dict.items()

dict.keys()

dict.pop()

dict.update()

dict.values()
Wekanta
Dictionary Cont'd
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

product = {'name': 'sensor', 'price': 25.0}



product['name'] = 'device' # set 'name' to 'device'

print(product['name']) # temperature sensor

product.get('name') # sensor

product.keys() # ['name', 'price']

product.pop('name') # remove key 'name'

product.values() # ['sensor', 25.0]



product.update({'price': 20.0}) # update price value

product.items() # [ ['name', 'sensor'], ['price', 25.0] ]
Wekanta
Dictionary Hash Table
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

dict = {}

dict['a'] = 'alpha'

dict['o'] = 'omega'

dict['g'] = 'gamma'



print(dict[‘a']) # 'alpha'

print(dict)

# {'a': 'alpha', 'o': 'omega', 'g': 'gamma'}
Wekanta
Comparison
๏ Operator
๏ Logical
๏ Identity
Wekanta
Operator
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
== # Equal



!= # Not equal



<> # Not equal



>= # More than or equal



<= # Less than or equal



> # More than



< # Less than
Wekanta
Logical Comparison
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# Logical AND

a and b



# Logical OR

a or b



# Logical Negation

not a



# Compound

(a and not (a or b)
Wekanta
Identity Comparison
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# identity

1 is 1 == True



# non identity

1 is not '1' == True
Wekanta
Control Flow
๏ Conditional
๏ For Loop
๏ While Loop
๏ List Comprehension
Wekanta
Conditional
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

price = 25.0



if price >= 20:

print('Expensive')

elif 20 > price >= 10:

print('Cheap')

else:

print('Super Cheap')
Wekanta
For Loop
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

docs = { 'name': 'sensor', 'price': 25.0 }



# iterate by range

for x in range(10):

print(x)

# 0, 1, 2 ….



# iterate by element / dictionary keys

for doc in docs:

print(doc)

# name, price



# expanded for-loop

for k, v in docs:

print(k, v)
Wekanta
While Loop
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# infinite

while True:

print(‘running…’)



# conditional

while x < 10:

print(‘running…’)

x += 1
Wekanta
List Comprehension
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

docs = [{'name': 'Arduino', 'price': 180.0},

{'name': 'Raspberry Pi', 'price': 200.0}]



# common method

new_list = []

for d in docs:

if d['price'] < 200:

new_list.append(d['name'])



# list comprehension method

new_list = [d['name'] for d in docs if d[‘price'] < 200]

# ['Arduino']
Wekanta
Function
๏ Function Argument
๏ Arbitrary Argument
Wekanta
Function Argument
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# basic function

def my_function():

''' Function Documentation '''

pass



# keyword argument

def price_check(price, currency='MYR'):

''' Check Price '''

pass
Wekanta
Arbitrary Argument
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
*args is non-keyworded arguments

# my_function(1, 2, 3)



**kwargs is keyworded arguments

# my_function(price=42)

Wekanta
Arbitrary Argument Cont’d
# This is single line comment

'This is also single line comment'

'''

This is example of

multi-line comment.

'''
# example

def my_function(*args, **kwargs):

''' Function Documentation '''

for arg in args:

print(arg)



for key, value in kwargs.items():

print(key, value)



# usage

my_function(1, 2, currency='MYR')



# results

1

2

currency MYR
Wekanta
Q&A
Wekanta

More Related Content

What's hot

Groovy presentation
Groovy presentationGroovy presentation
Groovy presentationManav Prasad
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kianphelios
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to heroDiego Lemos
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLeSparkBiz
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)Core Lee
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 

What's hot (14)

Os Borger
Os BorgerOs Borger
Os Borger
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
Designing Ruby APIs
Designing Ruby APIsDesigning Ruby APIs
Designing Ruby APIs
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to hero
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
 
Ruby_Basic
Ruby_BasicRuby_Basic
Ruby_Basic
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
ppt18
ppt18ppt18
ppt18
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
ppt9
ppt9ppt9
ppt9
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 

Similar to Introduction to Python by Wekanta

String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeString handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in pythoneShikshak
 
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
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un UnixVpmv
 
Tech Days Paris Intoduction F# and Collective Intelligence
Tech Days Paris Intoduction F# and Collective IntelligenceTech Days Paris Intoduction F# and Collective Intelligence
Tech Days Paris Intoduction F# and Collective IntelligenceRobert Pickering
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of JavascriptUniverse41
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basicsLuigi De Russis
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 

Similar to Introduction to Python by Wekanta (20)

UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
 
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeString handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python basic
Python basicPython basic
Python basic
 
php_string.pdf
php_string.pdfphp_string.pdf
php_string.pdf
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
Lecture06
Lecture06Lecture06
Lecture06
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes 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
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un Unix
 
Python basics
Python basicsPython basics
Python basics
 
Tech Days Paris Intoduction F# and Collective Intelligence
Tech Days Paris Intoduction F# and Collective IntelligenceTech Days Paris Intoduction F# and Collective Intelligence
Tech Days Paris Intoduction F# and Collective Intelligence
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
 
07-PHP.pptx
07-PHP.pptx07-PHP.pptx
07-PHP.pptx
 
07-PHP.pptx
07-PHP.pptx07-PHP.pptx
07-PHP.pptx
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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 ...
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Introduction to Python by Wekanta

  • 1. Introduction to Python
 a readable, dynamic, pleasant, flexible, fast and powerful language. Murtadha Bazli Tukimat
 Developer/Founder at Wekanta
 bazli@wekanta.com Wekanta
  • 2. Overview ๏ Background ๏ Syntax ๏ Variables ๏ Data Structure ๏ Comparison ๏ Control Flow ๏ Function Wekanta
  • 3. What is Python? • Python is a dynamic, interpreted (bytecode-compiled) and multi-platform language • No type declarations of variables, parameters, functions, or methods in source code • Code become short and fast to compile Wekanta
  • 4. Why Python? • Machine learning, NLP and data scientific tools packages • From embedded system to the web applications
 (Web, GUI, Scripting, etc.) • A general purpose language 
 Read it more → https://goo.gl/ZwtjJV Wekanta
  • 5. Syntax ๏ Hello World! ๏ Indentation ๏ Naming Convention ๏ Comment Wekanta
  • 7. • Indentation affects code's meaning • End of the line means end of the statement • Inconsistent indentation == Syntax Error • Tabs vs Spaces?
 Spaces are the preferred indentation method. Indentation Wekanta
  • 8. Indentation Cont'd If foo:
 If bar:
 print('Hello World') else:
 print('Welcome to Python') Wekanta
  • 9. • b (single lowercase) • B (single uppercase) • lowercase • lower_case_underscore • UPPERCASE • UPPER_CASE_UNDERSCORE • CamelCase • mixedCase • Camel_Case_Underscore (ugly) Naming Convention Wekanta
  • 10. # This is single line comment ' This is also single line comment ' ' This is a single line comment too ' '''
 This is example of
 multi-line comment.
 ''' Comment Wekanta
  • 11. Variables ๏ String ๏ Number ๏ Boolean ๏ Null Wekanta
  • 12. String # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # declaration
 s = 'hello python'
 
 # methods
 s.lower() # return string lowercase version
 s.upper() # return string uppercase version
 s.strip() # remove trailing & leading whitespaces
 s.isalpha() # alphanumeric test
 s.isdigit() # digit/number test
 s.isspace() # spaces test
 s.startswith('hello') # check if string start with 'foo'
 s.endswith('python') # check if string ending with 'bar'
 s.find('hello') # return 'foo' index
 s.replace('hello', 'hi') # replace 'foo' with 'bar' string
 s.split('hello') # return list of substrings
 s.join(list) # opposite of split Wekanta
  • 13. String Cont'd # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 s = 'Hello, this is Python '
 
 s.lower() # 'hello, this is python '
 s.upper() # 'HELLO, THIS IS PYTHON '
 s.strip() # 'Hello, this is Python'
 s.lower().find('hello') # 0
 s.replace('this', 'that') # 'Hello, that is Python '
 s = s.split(',') # ['Hello', ' this is Python ']
 ','.join(s) # 'Hello, this is Python ' Wekanta
  • 14. Number # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # integer number
 year = 2010
 year = int('2010') # floating point number
 temperature = 27.6
 temperature = float('27.6') # fixed point number
 price = Decimal('12.50') Wekanta
  • 15. Boolean # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 is_python = True # cast to any variables
 is_python = bool(0)
 is_python = bool('check') Wekanta
  • 16. Null # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' optional_data = None Wekanta
  • 17. Data Structure ๏ List ๏ Dictionary Wekanta
  • 18. List # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # declaration
 list = []
 list = list() # methods
 list.append(element)
 list.extend(list2)
 list.insert(index, element)
 list.remove(element)
 list.pop(index)
 list.clear()
 list.index(element)
 list.count(element)
 list.sort()
 list.reverse()
 list.copy() Wekanta
  • 19. List Cont'd # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 list = ['bazli', 'hidayah', 'nabila']
 
 list.append('others')         # append 'others' at end
 list.extend(['yyy', 'zzz'])   # add list of element at end
 list.insert(0, 'xxx')         # insert 'xxx' at index 0 print(list)
 # ['xxx', 'bazli', 'hidayah', 'nabila', 'others', 'yyy', 'zzz']
 
 print(list.index('bazli'))    # 1
 list.remove('bazli')         # search and remove that element
 list.pop(1)                   # removes and returns 'larry' print(list.count('xxx')) # 1
 print(list)
 # ['xxx', 'nabila', 'others', 'yyy', 'zzz']
 Wekanta
  • 20. List Slices # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 list = ['a', 'b', 'c', 'd']
 
 print(list[1:-1])  # ['b', 'c']
 print(list[:-1])   # ['a', 'b', 'c']
 
 list[0:2] = 'z'    # replace ['a', 'b'] with 'z'
 
 print(list)        # ['z', 'c', 'd'] Wekanta
  • 21. Dictionary # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # declaration
 dict = {}
 dict = dict()
 
 # methods
 dict.clear()
 dict.copy()
 dict.get()
 dict.items()
 dict.keys()
 dict.pop()
 dict.update()
 dict.values() Wekanta
  • 22. Dictionary Cont'd # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 product = {'name': 'sensor', 'price': 25.0}
 
 product['name'] = 'device' # set 'name' to 'device'
 print(product['name']) # temperature sensor
 product.get('name') # sensor
 product.keys() # ['name', 'price']
 product.pop('name') # remove key 'name'
 product.values() # ['sensor', 25.0]
 
 product.update({'price': 20.0}) # update price value
 product.items() # [ ['name', 'sensor'], ['price', 25.0] ] Wekanta
  • 23. Dictionary Hash Table # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 dict = {}
 dict['a'] = 'alpha'
 dict['o'] = 'omega'
 dict['g'] = 'gamma'
 
 print(dict[‘a']) # 'alpha'
 print(dict)
 # {'a': 'alpha', 'o': 'omega', 'g': 'gamma'} Wekanta
  • 25. Operator # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' == # Equal
 
 != # Not equal
 
 <> # Not equal
 
 >= # More than or equal
 
 <= # Less than or equal
 
 > # More than
 
 < # Less than Wekanta
  • 26. Logical Comparison # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # Logical AND
 a and b
 
 # Logical OR
 a or b
 
 # Logical Negation
 not a
 
 # Compound
 (a and not (a or b) Wekanta
  • 27. Identity Comparison # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # identity
 1 is 1 == True
 
 # non identity
 1 is not '1' == True Wekanta
  • 28. Control Flow ๏ Conditional ๏ For Loop ๏ While Loop ๏ List Comprehension Wekanta
  • 29. Conditional # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 price = 25.0
 
 if price >= 20:
 print('Expensive')
 elif 20 > price >= 10:
 print('Cheap')
 else:
 print('Super Cheap') Wekanta
  • 30. For Loop # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 docs = { 'name': 'sensor', 'price': 25.0 }
 
 # iterate by range
 for x in range(10):
 print(x)
 # 0, 1, 2 ….
 
 # iterate by element / dictionary keys
 for doc in docs:
 print(doc)
 # name, price
 
 # expanded for-loop
 for k, v in docs:
 print(k, v) Wekanta
  • 31. While Loop # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # infinite
 while True:
 print(‘running…’)
 
 # conditional
 while x < 10:
 print(‘running…’)
 x += 1 Wekanta
  • 32. List Comprehension # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 docs = [{'name': 'Arduino', 'price': 180.0},
 {'name': 'Raspberry Pi', 'price': 200.0}]
 
 # common method
 new_list = []
 for d in docs:
 if d['price'] < 200:
 new_list.append(d['name'])
 
 # list comprehension method
 new_list = [d['name'] for d in docs if d[‘price'] < 200]
 # ['Arduino'] Wekanta
  • 33. Function ๏ Function Argument ๏ Arbitrary Argument Wekanta
  • 34. Function Argument # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # basic function
 def my_function():
 ''' Function Documentation '''
 pass
 
 # keyword argument
 def price_check(price, currency='MYR'):
 ''' Check Price '''
 pass Wekanta
  • 35. Arbitrary Argument # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' *args is non-keyworded arguments
 # my_function(1, 2, 3)
 
 **kwargs is keyworded arguments
 # my_function(price=42) Wekanta
  • 36. Arbitrary Argument Cont’d # This is single line comment 'This is also single line comment' '''
 This is example of
 multi-line comment.
 ''' # example
 def my_function(*args, **kwargs):
 ''' Function Documentation '''
 for arg in args:
 print(arg)
 
 for key, value in kwargs.items():
 print(key, value)
 
 # usage
 my_function(1, 2, currency='MYR')
 
 # results
 1
 2
 currency MYR Wekanta