SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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 - Preliminarygo-lang
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operationsarchikabhatia
 
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++17Daniel Eriksson
 
Python 如何執行
Python 如何執行Python 如何執行
Python 如何執行kao kuo-tung
 
Coding convention
Coding conventionCoding convention
Coding conventionKhoa Nguyen
 
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
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional ProgrammingYiguang Hu
 
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?Kevin Pilch
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpen Gurukul
 
Lua زبان برنامه نویسی
Lua زبان برنامه نویسی Lua زبان برنامه نویسی
Lua زبان برنامه نویسی Shiraz LUG
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?Inada Naoki
 
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 filesramya marichamy
 

La actualidad más candente (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
 

Destacado

Getting started with ubuntu
Getting started with ubuntuGetting started with ubuntu
Getting started with ubuntuAbhinav Upadhyay
 
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 2012Jimmy Lai
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For ManagersAtul Shridhar
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
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 protesisOsvaldo Toscano ILTEC
 

Destacado (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
 

Similar a Python intro

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
 
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.pptxsangeeta borde
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.Mosky Liu
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobikrmboya
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with PythonSushant Mane
 
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
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
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
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.supriyasarkar38
 
1. python programming
1. python programming1. python programming
1. python programmingsreeLekha51
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxGaneshRaghu4
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 

Similar a 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
 

Último

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

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