SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Introduction to Python


                 Abhinav Upadhyay
           <abhinav@socialtwist.com>
What is Python
●   A dynamically typed, object oriented
    programmnig language
●   Created by Guido van Rossum in 1989
Features
●   High-level
●   Object Oriented
●   Scalable
●   Extensible
●   Portable
●   Readable
●   Managed runtime
●   Interpreted and Byte-compiled.
Difference from C Style Languages
●   Forget ; and {}
●   Embrace indentation
Getting Started
●   “Hello, World” in Python:

        print 'Hello, world!'
Getting Started
●   Redirecting your output

        file = open('output', 'w')
        print >> file, 'Hello, world!'
Making your program interactive
●   Getting user input:

        name = raw_input('Enter your name: ')
        print name
Comments in Python
●   Single line comments --> #
●   Multiline comments --> ''' your comment '''
●   Docstrings
Operators
●   Numerical operators: +, -, /, //, *, **, %

●   Comparision operators: <, >, <=, >=, ==, !=, <>

●   Logical operators: and, or, not
Numerical types in Python
●   int
    –     long
    –     float


●   bool

●   complex
String handling in Python
●   Creating a string:

         my_string = “this is a string”

         my_2nd_string = 'string using single
         quotes'

         my_3rd_string = ''' triple quotes also
         work'''
String handling in Python
●   String operators:
        + --> Performs concatenation
              str1 = 'a'
              str2 = 'b'
              print a + b
              Output: 'ab'
        * --> Performs repitition
              str1 = 'a'
              print a * 5
              Output: 'aaaaa'
String handling in Python
●   String operators:

        % --> Format operator
              age = 20
              str1 = 'Your age is %dn' % age
              Output: 'Your age is 20'
String handling in Python
●   String Manipulation:
    –   Indices starting from 0
    –   Indices from last element starting with -1

          str1 = 'hello, world'
          print str1[0]
          Output: 'h'
          print str[-1]
          Output: 'd'
          Print str[-2]
          Output: 'l'
String handling in Python
Slicing:
  ●   Use the slicing operator [] to slice the string into smaller
      parts
  ●   Syntax: str[m:n]
       –   This will print the characters of the string starting from the mth position till
           the nth position (but excluding the nth character)

           str1 = '0123456789'
           print str1[1:4]
           Output: 123
Built-in functions of Python
●   Functions which are built-in to the Python
    interpreter and are always available
●   Examples: pow(), print(), open(), int(), str(),
    etc.

●   Some useful BIFs:
    –   type(), help(), dir()
Common Python Data-Structures
●   Lists:
    –   Array like data-structure
    –   Objects stored in sequential order
    –   Indices starting from 0
    –   Can store arbitrary number of objects (unlike fixed
        length arrays in other languages)
    –   Can also store objects of different types in the
        same list.
Common Python Data-Structures
●   Tuples:
    –   Similar to lists, with two visible differences:
         ●   Lists use [], while tuples use () in their syntax
         ●   Tuples are immutable data-structures
Common Python Data-Structures
●   Dictionaries:
    –   Hash tables
    –   Can store any number of objects
    –   {} are used for creating dictionaries
Loops in Python
●   For loop:
      Used for iterating over a sequence of items
      for item in list:
        print item
Loops in Python
●   While loop:
      Used for executing a suite of code a number
      of times.
      Count = 0
      while count < 10:
        print count
        count += 1
Conditionals
●   If-elif-else
      if <condition>:
         #statement1
         #statement2
      elif <condition 2>:
         #statement3
         #statement4
      else:
         pass
File handling

F = open('file1.txt', 'r')
for eachLine in F:
  print F
F.close()

f = open('file2.txt', 'w')
f.write('hello, worldn')
f.close()
Functions in Python
●   The 'def' keyword
●   The return value
●   Returning multiple values
Python intro

Contenu connexe

Tendances

Python session 4 subprocess- by Gopal.A (Python developer)
Python session 4 subprocess- by Gopal.A (Python developer)Python session 4 subprocess- by Gopal.A (Python developer)
Python session 4 subprocess- by Gopal.A (Python developer)
Navaneethan Naveen
 

Tendances (19)

Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
C++ quik notes
C++ quik notesC++ quik notes
C++ quik notes
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
Welcome vibrant-technology-navimumbai
Welcome vibrant-technology-navimumbaiWelcome vibrant-technology-navimumbai
Welcome vibrant-technology-navimumbai
 
Welcome vibrant-technology-navimumbai
Welcome vibrant-technology-navimumbaiWelcome vibrant-technology-navimumbai
Welcome vibrant-technology-navimumbai
 
Meetup C++ A brief overview of c++17
Meetup C++  A brief overview of c++17Meetup C++  A brief overview of c++17
Meetup C++ A brief overview of c++17
 
Python 如何執行
Python 如何執行Python 如何執行
Python 如何執行
 
Coding convention
Coding conventionCoding convention
Coding convention
 
Python session 4 subprocess- by Gopal.A (Python developer)
Python session 4 subprocess- by Gopal.A (Python developer)Python session 4 subprocess- by Gopal.A (Python developer)
Python session 4 subprocess- by Gopal.A (Python developer)
 
FTD JVM Internals
FTD JVM InternalsFTD JVM Internals
FTD JVM Internals
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Lua زبان برنامه نویسی
Lua زبان برنامه نویسی Lua زبان برنامه نویسی
Lua زبان برنامه نویسی
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 

En vedette (8)

Linux programming
Linux programmingLinux programming
Linux programming
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Getting started with ubuntu
Getting started with ubuntuGetting started with ubuntu
Getting started with ubuntu
 
When big data meet python @ COSCUP 2012
When big data meet python @ COSCUP 2012When big data meet python @ COSCUP 2012
When big data meet python @ COSCUP 2012
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For Managers
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Materiales mas utilizados en ortesis y protesis
Materiales mas utilizados en ortesis y protesisMateriales mas utilizados en ortesis y protesis
Materiales mas utilizados en ortesis y protesis
 
Ortesis de mano
Ortesis de manoOrtesis de mano
Ortesis de mano
 

Similaire à Python intro

INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
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
usvirat1805
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
gabriellekuruvilla
 
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
 

Similaire à Python intro (20)

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
PythonPython
Python
 
Python
PythonPython
Python
 
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
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Python ppt
Python pptPython ppt
Python ppt
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
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
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
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...
 
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.
 
1. python programming
1. python programming1. python programming
1. python programming
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Python intro

  • 1. Introduction to Python Abhinav Upadhyay <abhinav@socialtwist.com>
  • 2. What is Python ● A dynamically typed, object oriented programmnig language ● Created by Guido van Rossum in 1989
  • 3. Features ● High-level ● Object Oriented ● Scalable ● Extensible ● Portable ● Readable ● Managed runtime ● Interpreted and Byte-compiled.
  • 4. Difference from C Style Languages ● Forget ; and {} ● Embrace indentation
  • 5. Getting Started ● “Hello, World” in Python: print 'Hello, world!'
  • 6. Getting Started ● Redirecting your output file = open('output', 'w') print >> file, 'Hello, world!'
  • 7. Making your program interactive ● Getting user input: name = raw_input('Enter your name: ') print name
  • 8. Comments in Python ● Single line comments --> # ● Multiline comments --> ''' your comment ''' ● Docstrings
  • 9. Operators ● Numerical operators: +, -, /, //, *, **, % ● Comparision operators: <, >, <=, >=, ==, !=, <> ● Logical operators: and, or, not
  • 10. Numerical types in Python ● int – long – float ● bool ● complex
  • 11. String handling in Python ● Creating a string: my_string = “this is a string” my_2nd_string = 'string using single quotes' my_3rd_string = ''' triple quotes also work'''
  • 12. String handling in Python ● String operators: + --> Performs concatenation str1 = 'a' str2 = 'b' print a + b Output: 'ab' * --> Performs repitition str1 = 'a' print a * 5 Output: 'aaaaa'
  • 13. String handling in Python ● String operators: % --> Format operator age = 20 str1 = 'Your age is %dn' % age Output: 'Your age is 20'
  • 14. String handling in Python ● String Manipulation: – Indices starting from 0 – Indices from last element starting with -1 str1 = 'hello, world' print str1[0] Output: 'h' print str[-1] Output: 'd' Print str[-2] Output: 'l'
  • 15. String handling in Python Slicing: ● Use the slicing operator [] to slice the string into smaller parts ● Syntax: str[m:n] – This will print the characters of the string starting from the mth position till the nth position (but excluding the nth character) str1 = '0123456789' print str1[1:4] Output: 123
  • 16. Built-in functions of Python ● Functions which are built-in to the Python interpreter and are always available ● Examples: pow(), print(), open(), int(), str(), etc. ● Some useful BIFs: – type(), help(), dir()
  • 17. Common Python Data-Structures ● Lists: – Array like data-structure – Objects stored in sequential order – Indices starting from 0 – Can store arbitrary number of objects (unlike fixed length arrays in other languages) – Can also store objects of different types in the same list.
  • 18. Common Python Data-Structures ● Tuples: – Similar to lists, with two visible differences: ● Lists use [], while tuples use () in their syntax ● Tuples are immutable data-structures
  • 19. Common Python Data-Structures ● Dictionaries: – Hash tables – Can store any number of objects – {} are used for creating dictionaries
  • 20. Loops in Python ● For loop: Used for iterating over a sequence of items for item in list: print item
  • 21. Loops in Python ● While loop: Used for executing a suite of code a number of times. Count = 0 while count < 10: print count count += 1
  • 22. Conditionals ● If-elif-else if <condition>: #statement1 #statement2 elif <condition 2>: #statement3 #statement4 else: pass
  • 23. File handling F = open('file1.txt', 'r') for eachLine in F: print F F.close() f = open('file2.txt', 'w') f.write('hello, worldn') f.close()
  • 24. Functions in Python ● The 'def' keyword ● The return value ● Returning multiple values