SlideShare une entreprise Scribd logo
1  sur  84
Télécharger pour lire hors ligne
Programming is Fun
     An introduction to Python


Indian Linux Users Group Coimbatore
         http://ilugcbe.org.in
       mail2ilugcbe@gmail.com




         ILUG-CBE   Programming is Fun
Our Inspiration


   Kenneth Gonsalves (1953-2012)




                          ILUG-CBE   Programming is Fun
About




        ILUG-CBE   Programming is Fun
Purpose




      Learn art of computer programming with one of the easiest
      programming language in the world.
      Get ready to enjoy the joy of programming in Python.




                         ILUG-CBE   Programming is Fun
Warning


      This is a hands on training program.
      No theory included in the slides; it may discussed whenever
      and wherever it is required.
      Be patient,listen, practice and ask questions
      Do not hesitate to experiment
      Our volunteers are here to help you in practising
      Be courageous enough to try
      We are leaning Python not rocket science
      Be simple and think in a simplistic way

  Are You Ready !



                           ILUG-CBE   Programming is Fun
Why Python



  Why
        Used almost everywhere
        Fun
        Concise
        Simple
        Powerful
        Filled with spices to write effective programs




                            ILUG-CBE   Programming is Fun
Installation




   Already installed in GNU/Linux systems
   If you are using M$ Windows download Python from python.org
   If you are downloading Python for Windows remember to
   download Python 2.7 only.




                          ILUG-CBE   Programming is Fun
Interactive Interpreter




  ILUG-CBE   Programming is Fun
Interpreter




   Contains REPL
       Read
       Evaluate
       Print
       Loop




                   ILUG-CBE   Programming is Fun
Interpreter




              ILUG-CBE   Programming is Fun
Hello World!!




   Why Hello World
   Writing ’Hello World’ program is the ritual to please the
   programming gods to be a good programmer!!

     >>> print "Hello World"
     Hello world




                            ILUG-CBE   Programming is Fun
Let’s Jump to Programming




                    ILUG-CBE   Programming is Fun
Programming Practice - 1




   Create a file hello.py
   type print ”Hello World”
   Listen to the screen for instructions.
   In-case of any issues just raise your hand our volunteers will be
   there to help you.




                             ILUG-CBE   Programming is Fun
Programming Practice - 1




   Run the program

     $python hello.py




                        ILUG-CBE   Programming is Fun
Time to make your hands dirty




   Note
   Make sure that you have understood the first step.
   In-case of trouble we can practice it for couple of minutes.




                             ILUG-CBE   Programming is Fun
Variables




     age = 33                    #   Integer
     avg = 33.35                 #   Float
     name = "linux"              #   String
     bool = True                 #   Boolean
     another = "44"              #   String




                      ILUG-CBE       Programming is Fun
Variables - naming




      use lowercase
      use underscore between words my age
      do not start with numbers
      do not use built-ins
      do not use keywords




                             ILUG-CBE   Programming is Fun
Reserved




   and del for is raise assert elif from lambda return break else global
   not try class except if or while continue exec import pass yield def
   finally in print




                             ILUG-CBE   Programming is Fun
Time to make your hands dirty




                     ILUG-CBE   Programming is Fun
Everything is an object
       Everything in python is an object
   An object has
       identity (id)
       type (type)
       value (mutable or immutable)

     >>> age = 33
     >>> type(age)
     <type ’int’>
     >>> id(age)
     167263248
     >>> age 34
     >>> id(age)
     167263236

                           ILUG-CBE   Programming is Fun
Casting




     >>> age = 33
     >>> str(age)
     ’33’
     >>> float(age)
     33.0
     >>> long(age)
     33L
     >>> int(age)
     33


                      ILUG-CBE   Programming is Fun
Time for some maths




   + , - , * , ** (power),% (modulo), // (floor division), < (less than)
   > greater than, <=, >=, ==




                            ILUG-CBE   Programming is Fun
It is maths time now




                       ILUG-CBE   Programming is Fun
String




     >>> name = ’linux’
     >>> address = "Coimbatore 1st street"
     >>> description = """ We are teaching python to
     young chaps"""
     >>> with_new = "this sentence have one n new line"




                       ILUG-CBE   Programming is Fun
String



     >>>   name = "linux"
     >>>   nameu = name.upper()
     >>>   namel = nameu.lower()
     >>>   namel.find(’l’)
     >>>   ",".join(name)
     >>>   name.startswith(’l’)
     >>>   name.endswith(’x’)
     >>>   namet = name.title()
     >>>   wspace = "     with space "
     >>>   stripped = wspace.strip()




                         ILUG-CBE   Programming is Fun
Playing with String




                      ILUG-CBE   Programming is Fun
Comments




     Single line comments starts with #
     Multi-line comments should be with in ””” ”””

    >>> avg = 45.34 #float
    >>> name = "ilug-cbe" """ This is a
    multiline comment """




                        ILUG-CBE   Programming is Fun
Boolean




    >>> t = True
    >>> f = Flase

    >>> n = None




                    ILUG-CBE   Programming is Fun
Conditionals




   equality,greater,less,is, is not ...
   ==, ! =, >, >=, <, <=, is, is not




                            ILUG-CBE   Programming is Fun
Conditionals



     >>>   1 == 1
     >>>   1 >= 0
     >>>   0 <= 1
     >>>   0 != 1
     >>>   "Rajani" is "rajani"
     >>>   "Vijay" is not "Rajani"
     >>>   name = None
     >>>   if name is not None:
     ...       #do something




                         ILUG-CBE   Programming is Fun
Boolean operators




   Used to combine conditional logic
       and
       or
       not




                           ILUG-CBE    Programming is Fun
if ...




         if mark > 60 and mark < 100:
           print "First Class"
         elif mark < 60:
           print "Second Class Only :-("
         else:
           print "Ooops !!!!"




                           ILUG-CBE   Programming is Fun
if ... elif time




                   ILUG-CBE   Programming is Fun
Sequences




  list
  List is an ordered collection of objects.

    names = ["rms","linus","guido","larry"]
    marks = [45,50,60,80,90]
    mixed = ["linux",12,12.35,90L]




                            ILUG-CBE   Programming is Fun
Sequences - list

     names = []
     print names
     names.append("linus")
     print names
     numbers = [6,9,2,3,1,8,4]
     print len(numbers)
     print numbers.sort()
     print numbers.reverse()
     another = [9,3,6]
     numbers.extend(another)
     print numbers
     numbers.insert(0,20)
     print numbers



                       ILUG-CBE   Programming is Fun
Sequences - list




     print   numbers[0]
     print   numbers[-1]
     print   numbers[2:-2]
     print   numbers[:-2]
     print   numbers[2:]
     print   numbers[:]




                         ILUG-CBE   Programming is Fun
Sequences -tuple



   tuple
   Tuple is like list only. But tuple is immutable

     nums = (1,2,3,4)
     print nums
     print len(nums)
     print nums[0]
     print nums[-1]




                             ILUG-CBE   Programming is Fun
Sequences range




    nums = range(20)
    print nums
    selected = range(20,60)
    print selected
    jump2 = range(10,100,2)
    print jump2




                      ILUG-CBE   Programming is Fun
Let’s do some sequencing




                     ILUG-CBE   Programming is Fun
Iteration




     names = ["linus","rms","guido","larry"]
     for name in names:
       print "hello %s" %(name)

     for num in range(10,20,2):
       print num




                       ILUG-CBE   Programming is Fun
Iteration




     for i in range(len(names)):
       print i,names[i]

     for i,v in enumerate(names):
       print i,v




                       ILUG-CBE   Programming is Fun
Iteration break,continue and pass

     for name in names:
       print name
       if name == "guido":
         break


     for name in names:
       print name
       if name == "linus":
         continue

     for name in names:
       print name
       if name == "rms":
         pass

                       ILUG-CBE   Programming is Fun
Iteration - while




     my_number = 10

     while my_number < 20:
        print my_number
        my_number += 2




                       ILUG-CBE   Programming is Fun
Let’s Iterate




                ILUG-CBE   Programming is Fun
Dictionaries




   Also called as hash, hashmap or associative array

     address = {"name":"ILUG-CBE","houseno":"Nil",
     "street":"any whare","city":"Coimbatore"}
     print address




                            ILUG-CBE   Programming is Fun
Dictionaries




     address["state"] = "tamilnadu"
     address["web"] = "ilugcbe.org.in"

     print address




                       ILUG-CBE   Programming is Fun
Dictionaries




     print address.has_key("country")

     print address.get("phone","No Phone Number Provided")




                       ILUG-CBE   Programming is Fun
Dictionaries

     address.setdefault("country","India")

     print address

     print address.keys()

     print address.values()

     print address.items()

     del address["country"]

     print address



                       ILUG-CBE   Programming is Fun
Let’s practice Dictionaries




                        ILUG-CBE   Programming is Fun
Functions




     def say_hai():
       print "hello"

     say_hai()




                       ILUG-CBE   Programming is Fun
Functions




     def add_two(num):
       return num + 2

     res = add_two(4)

     print res




                         ILUG-CBE   Programming is Fun
Functions



     def add(a,b):
       """
       adds two numbers
       """
       return a + b

     res = add_two(4,5)

     print res




                          ILUG-CBE   Programming is Fun
Functions



     def demo(*args):
       """
       *args demo
       """
       for arg in args:
         print i * 2

     demo(1,2,3,4,5,6)




                          ILUG-CBE   Programming is Fun
Functions



     def demo(num,*args):
       """
       *args demo
       """
       for arg in args:
         print i * num

     demo(1,2,3,4,5,6)




                         ILUG-CBE   Programming is Fun
Functions

     def demo(num,*args):
       """
       *args demo
       """
       mul = []
       for arg in args:
         mul.append(i * num)

      return sum(mul)

     res = demo(2,2,3,4,5,6)

     print res



                        ILUG-CBE   Programming is Fun
Functions




     def marker(roll_no,details):
       if details[’marks’] > 60:
         print "Roll no %d %s" %(roll_no, "First Class")

     marker(12,marks = 62)




                       ILUG-CBE   Programming is Fun
Functions



     def mulbythree(num,three=3):
       """
       default argument example
       """
       return num * three

     res = mulbythree(43)
     print res




                       ILUG-CBE   Programming is Fun
Be functional now




                    ILUG-CBE   Programming is Fun
Tricks 1




     nums = [1,2,3,4,5,6,7,8,9]
     mulbt = [num * 2 for num in nums]

     print nums
     print mulbt




                       ILUG-CBE   Programming is Fun
Tricks - 2




     nums = [1,2,3,4,5,6,7,8,9]
     mulbt = [num * 2 for num in nums if num / 2 != 0]

     print nums
     print mulbt




                       ILUG-CBE   Programming is Fun
Tricks - 3




     nums = [1,2,3,4,5,6,7,8,9]
     numtuple = tuple(nums)

     print type(nums)
     print type(numtuple)




                       ILUG-CBE   Programming is Fun
Tricks - 4




     print "ILUGCBE".lower().upper().title()




                       ILUG-CBE   Programming is Fun
User input



     name = raw_input("Tell your name: ")

     print name

     age = int(raw_input("Tell your age: "))

     print age




                       ILUG-CBE   Programming is Fun
Tricks time




              ILUG-CBE   Programming is Fun
Lambda




    product = lambda x,y : x * y

    res = product(12,13)
    print res




                      ILUG-CBE   Programming is Fun
Lambda




    dbtnt = lambda x : x * 2 if x % 2 == 0 else x

    res = dbtnt(12)
    print res




                      ILUG-CBE   Programming is Fun
Lambda




    bors = lambda x: x > 100 and ’big’ or ’small’

    for i in (1, 10, 99, 100, 101, 110):
        print i, ’is’, f(i)




                      ILUG-CBE   Programming is Fun
Object Oriented Programming - basics


     class MyClass:
         """
         This is my class
         """
         def __init__(self):
             #nothing

         def say_hai(self):
             print "Hai"

      obj = MyClass()
      obj.say_hai()



                        ILUG-CBE   Programming is Fun
Object Oriented Programming - basics


     class MyClass(object):
         """
         This is my class
         """
         def __init__(self):
             #nothing

         def say_hai(self):
             print "Hai"

      obj = MyClass()
      obj.say_hai()



                        ILUG-CBE   Programming is Fun
Object Oriented Programming - basics

     class Student:
         """
         Student class
         """

         def __init__(self):
             self.college = "My College"

         def greet(self,name):
             """
             Function to greet student
             """
             print "Hello %s from %s" %(name, self.college)

      student = Student()
      student.greet("Jaganadh")
                         ILUG-CBE   Programming is Fun
Object Oriented Programming - inheritance


     class BeStudent:
         def __init__(self):
             Student.__init__(self)
             self.class = "BE First Year"

         def greet(self,name):
             print "Hello %s from %s %s class" %(name,
             self.college,self.class)

      student = BeStudent()
      student.greet("Jaganadh G")




                      ILUG-CBE   Programming is Fun
Object Oriented Time




                       ILUG-CBE   Programming is Fun
File I/O - read file


     input = open("file.txt",’r’)
     contents = input.read()
     input.close()

     print contents

     input = open("file.txt",’r’)
     contents = input.readlines()
     input.close()

     print contents




                       ILUG-CBE   Programming is Fun
File I/O - write to file




     names = ["linus","rms","larry","guido"]
     output = open("out_file.txt",’w’)
     for name in names:
         output.write(name)
         output.write("n")




                          ILUG-CBE   Programming is Fun
File I/O - write to file




     names = ["linus","rms","larry","guido"]
     output = open("out_file.txt",’a’)
     for name in names:
         output.write(name)
         output.write("n")




                          ILUG-CBE   Programming is Fun
Let’s play with files




                       ILUG-CBE   Programming is Fun
Batteries

   Standard Libraries
   Python comes with batteries included. Lots of useful libraries are
   there in the language. Let’s see some of these libraries now

      import math
      print math.pi
      print math.sqrt(10)
      print math.factorial(10)
      print math.sin(10)
      print math.pow(10,2)
      print math.log(10)
      print math.log(10,2)
      print math.log10(10)
      print math.exp(10)


                            ILUG-CBE   Programming is Fun
Batteries - sys




    import sys
    print sys.platform

    afl = sys.argv[1]

    print sys.version
    print sys.maxint
    print sys.maxsize




                         ILUG-CBE   Programming is Fun
Batteries - os




    import os
    print os.curdir()
    print os.getlogin()
    print os.getcwd()
    print os.name




                          ILUG-CBE   Programming is Fun
Batteries - time,random




    import time
    print time.ctime()
    print time.gmtime()

    import random
    print random.random()
    print random.choice([1,2,3,4,5,6])




                          ILUG-CBE   Programming is Fun
Battery Recharge




                   ILUG-CBE   Programming is Fun
Question Time




                ILUG-CBE   Programming is Fun
Contributors




      Jaganadh G @jaganadhg
      Biju B @bijubk
      Satheesh Kumar D
      Sreejith S @tweet2sree
      Rajith Ravi @chelakkandupoda




                          ILUG-CBE   Programming is Fun
Contact US




  Web
  http://ilugcbe.org.in
  mail mail2ilugcbe@gmail.com




                         ILUG-CBE   Programming is Fun

Contenu connexe

En vedette

A 12 hour workshop on Introduction to Python
A 12 hour workshop on Introduction to PythonA 12 hour workshop on Introduction to Python
A 12 hour workshop on Introduction to PythonSatyaki Sikdar
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
Lecture 2 introduction to python
Lecture 2  introduction to pythonLecture 2  introduction to python
Lecture 2 introduction to pythonalvin567
 
Workshop on Programming in Python - day II
Workshop on Programming in Python - day IIWorkshop on Programming in Python - day II
Workshop on Programming in Python - day IISatyaki Sikdar
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & styleKevlin Henney
 
Natural Language Processing with Per
Natural Language Processing with PerNatural Language Processing with Per
Natural Language Processing with PerJaganadh Gopinadhan
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersKevlin Henney
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 
Python入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニングPython入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニングYuichi Ito
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Simple Steps to UX/UI Web Design
Simple Steps to UX/UI Web DesignSimple Steps to UX/UI Web Design
Simple Steps to UX/UI Web DesignKoombea
 

En vedette (14)

A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
A 12 hour workshop on Introduction to Python
A 12 hour workshop on Introduction to PythonA 12 hour workshop on Introduction to Python
A 12 hour workshop on Introduction to Python
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Lecture 2 introduction to python
Lecture 2  introduction to pythonLecture 2  introduction to python
Lecture 2 introduction to python
 
Python introduction
Python introductionPython introduction
Python introduction
 
Workshop on Programming in Python - day II
Workshop on Programming in Python - day IIWorkshop on Programming in Python - day II
Workshop on Programming in Python - day II
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
Natural Language Processing with Per
Natural Language Processing with PerNatural Language Processing with Per
Natural Language Processing with Per
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 
Python入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニングPython入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニング
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Simple Steps to UX/UI Web Design
Simple Steps to UX/UI Web DesignSimple Steps to UX/UI Web Design
Simple Steps to UX/UI Web Design
 

Similaire à Intro to Python Programming with ILUG-CBE

Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
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
 
Notes1
Notes1Notes1
Notes1hccit
 
python-an-introduction
python-an-introductionpython-an-introduction
python-an-introductionShrinivasan T
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School ProgrammersSiva Arunachalam
 
Python An Intro
Python An IntroPython An Intro
Python An IntroArulalan T
 
Class 3: if/else
Class 3: if/elseClass 3: if/else
Class 3: if/elseMarc Gouw
 
Functional pogramming hl overview
Functional pogramming hl overviewFunctional pogramming hl overview
Functional pogramming hl overviewElad Avneri
 
Programming with python
Programming with pythonProgramming with python
Programming with pythonsarogarage
 
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
 
Python language data types
Python language data typesPython language data types
Python language data typesHarry Potter
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesFraboni Ec
 
Python language data types
Python language data typesPython language data types
Python language data typesJames Wong
 

Similaire à Intro to Python Programming with ILUG-CBE (20)

Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
Python 101 1
Python 101   1Python 101   1
Python 101 1
 
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...
 
ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 
Python slide
Python slidePython slide
Python slide
 
3.Pi for Python
3.Pi for Python3.Pi for Python
3.Pi for Python
 
Python.pdf
Python.pdfPython.pdf
Python.pdf
 
Notes1
Notes1Notes1
Notes1
 
Python Loop
Python LoopPython Loop
Python Loop
 
python-an-introduction
python-an-introductionpython-an-introduction
python-an-introduction
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Python An Intro
Python An IntroPython An Intro
Python An Intro
 
Class 3: if/else
Class 3: if/elseClass 3: if/else
Class 3: if/else
 
Functional pogramming hl overview
Functional pogramming hl overviewFunctional pogramming hl overview
Functional pogramming hl overview
 
Programming with python
Programming with pythonProgramming with python
Programming with 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
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 

Plus de Jaganadh Gopinadhan

Introduction to Sentiment Analysis
Introduction to Sentiment AnalysisIntroduction to Sentiment Analysis
Introduction to Sentiment AnalysisJaganadh Gopinadhan
 
Elements of Text Mining Part - I
Elements of Text Mining Part - IElements of Text Mining Part - I
Elements of Text Mining Part - IJaganadh Gopinadhan
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language ProcessingJaganadh Gopinadhan
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language ProcessingJaganadh Gopinadhan
 
Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org Jaganadh Gopinadhan
 
Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic Jaganadh Gopinadhan
 
Script to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latestScript to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latestJaganadh Gopinadhan
 
A tutorial on Machine Translation
A tutorial on Machine TranslationA tutorial on Machine Translation
A tutorial on Machine TranslationJaganadh Gopinadhan
 
Linguistic localization framework for Ooo
Linguistic localization framework for OooLinguistic localization framework for Ooo
Linguistic localization framework for OooJaganadh Gopinadhan
 
ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands Jaganadh Gopinadhan
 
Introduction to Free and Open Source Software
Introduction to Free and Open Source Software Introduction to Free and Open Source Software
Introduction to Free and Open Source Software Jaganadh Gopinadhan
 
Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges Jaganadh Gopinadhan
 
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...Jaganadh Gopinadhan
 
Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining Jaganadh Gopinadhan
 
Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications Jaganadh Gopinadhan
 

Plus de Jaganadh Gopinadhan (20)

Introduction to Sentiment Analysis
Introduction to Sentiment AnalysisIntroduction to Sentiment Analysis
Introduction to Sentiment Analysis
 
Elements of Text Mining Part - I
Elements of Text Mining Part - IElements of Text Mining Part - I
Elements of Text Mining Part - I
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language Processing
 
Practical Natural Language Processing
Practical Natural Language ProcessingPractical Natural Language Processing
Practical Natural Language Processing
 
Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org Indian Language Spellchecker Development for OpenOffice.org
Indian Language Spellchecker Development for OpenOffice.org
 
Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic Sanskrit and Computational Linguistic
Sanskrit and Computational Linguistic
 
Script to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latestScript to Sentiment : on future of Language TechnologyMysore latest
Script to Sentiment : on future of Language TechnologyMysore latest
 
A tutorial on Machine Translation
A tutorial on Machine TranslationA tutorial on Machine Translation
A tutorial on Machine Translation
 
Linguistic localization framework for Ooo
Linguistic localization framework for OooLinguistic localization framework for Ooo
Linguistic localization framework for Ooo
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Social Media Analytics
Social Media Analytics Social Media Analytics
Social Media Analytics
 
Success Factor
Success Factor Success Factor
Success Factor
 
ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands ntroduction to GNU/Linux Linux Installation and Basic Commands
ntroduction to GNU/Linux Linux Installation and Basic Commands
 
Introduction to Free and Open Source Software
Introduction to Free and Open Source Software Introduction to Free and Open Source Software
Introduction to Free and Open Source Software
 
Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges Opinion Mining and Sentiment Analysis Issues and Challenges
Opinion Mining and Sentiment Analysis Issues and Challenges
 
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
What they think about my brand/product ?!?!? An Introduction to Sentiment Ana...
 
Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining Tools andTechnologies for Large Scale Data Mining
Tools andTechnologies for Large Scale Data Mining
 
Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications Practical Natural Language Processing From Theory to Industrial Applications
Practical Natural Language Processing From Theory to Industrial Applications
 
Hdfs
HdfsHdfs
Hdfs
 
Mahout Tutorial FOSSMEET NITC
Mahout Tutorial FOSSMEET NITCMahout Tutorial FOSSMEET NITC
Mahout Tutorial FOSSMEET NITC
 

Dernier

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 

Dernier (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 

Intro to Python Programming with ILUG-CBE

  • 1. Programming is Fun An introduction to Python Indian Linux Users Group Coimbatore http://ilugcbe.org.in mail2ilugcbe@gmail.com ILUG-CBE Programming is Fun
  • 2. Our Inspiration Kenneth Gonsalves (1953-2012) ILUG-CBE Programming is Fun
  • 3. About ILUG-CBE Programming is Fun
  • 4. Purpose Learn art of computer programming with one of the easiest programming language in the world. Get ready to enjoy the joy of programming in Python. ILUG-CBE Programming is Fun
  • 5. Warning This is a hands on training program. No theory included in the slides; it may discussed whenever and wherever it is required. Be patient,listen, practice and ask questions Do not hesitate to experiment Our volunteers are here to help you in practising Be courageous enough to try We are leaning Python not rocket science Be simple and think in a simplistic way Are You Ready ! ILUG-CBE Programming is Fun
  • 6. Why Python Why Used almost everywhere Fun Concise Simple Powerful Filled with spices to write effective programs ILUG-CBE Programming is Fun
  • 7. Installation Already installed in GNU/Linux systems If you are using M$ Windows download Python from python.org If you are downloading Python for Windows remember to download Python 2.7 only. ILUG-CBE Programming is Fun
  • 8. Interactive Interpreter ILUG-CBE Programming is Fun
  • 9. Interpreter Contains REPL Read Evaluate Print Loop ILUG-CBE Programming is Fun
  • 10. Interpreter ILUG-CBE Programming is Fun
  • 11. Hello World!! Why Hello World Writing ’Hello World’ program is the ritual to please the programming gods to be a good programmer!! >>> print "Hello World" Hello world ILUG-CBE Programming is Fun
  • 12. Let’s Jump to Programming ILUG-CBE Programming is Fun
  • 13. Programming Practice - 1 Create a file hello.py type print ”Hello World” Listen to the screen for instructions. In-case of any issues just raise your hand our volunteers will be there to help you. ILUG-CBE Programming is Fun
  • 14. Programming Practice - 1 Run the program $python hello.py ILUG-CBE Programming is Fun
  • 15. Time to make your hands dirty Note Make sure that you have understood the first step. In-case of trouble we can practice it for couple of minutes. ILUG-CBE Programming is Fun
  • 16. Variables age = 33 # Integer avg = 33.35 # Float name = "linux" # String bool = True # Boolean another = "44" # String ILUG-CBE Programming is Fun
  • 17. Variables - naming use lowercase use underscore between words my age do not start with numbers do not use built-ins do not use keywords ILUG-CBE Programming is Fun
  • 18. Reserved and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print ILUG-CBE Programming is Fun
  • 19. Time to make your hands dirty ILUG-CBE Programming is Fun
  • 20. Everything is an object Everything in python is an object An object has identity (id) type (type) value (mutable or immutable) >>> age = 33 >>> type(age) <type ’int’> >>> id(age) 167263248 >>> age 34 >>> id(age) 167263236 ILUG-CBE Programming is Fun
  • 21. Casting >>> age = 33 >>> str(age) ’33’ >>> float(age) 33.0 >>> long(age) 33L >>> int(age) 33 ILUG-CBE Programming is Fun
  • 22. Time for some maths + , - , * , ** (power),% (modulo), // (floor division), < (less than) > greater than, <=, >=, == ILUG-CBE Programming is Fun
  • 23. It is maths time now ILUG-CBE Programming is Fun
  • 24. String >>> name = ’linux’ >>> address = "Coimbatore 1st street" >>> description = """ We are teaching python to young chaps""" >>> with_new = "this sentence have one n new line" ILUG-CBE Programming is Fun
  • 25. String >>> name = "linux" >>> nameu = name.upper() >>> namel = nameu.lower() >>> namel.find(’l’) >>> ",".join(name) >>> name.startswith(’l’) >>> name.endswith(’x’) >>> namet = name.title() >>> wspace = " with space " >>> stripped = wspace.strip() ILUG-CBE Programming is Fun
  • 26. Playing with String ILUG-CBE Programming is Fun
  • 27. Comments Single line comments starts with # Multi-line comments should be with in ””” ””” >>> avg = 45.34 #float >>> name = "ilug-cbe" """ This is a multiline comment """ ILUG-CBE Programming is Fun
  • 28. Boolean >>> t = True >>> f = Flase >>> n = None ILUG-CBE Programming is Fun
  • 29. Conditionals equality,greater,less,is, is not ... ==, ! =, >, >=, <, <=, is, is not ILUG-CBE Programming is Fun
  • 30. Conditionals >>> 1 == 1 >>> 1 >= 0 >>> 0 <= 1 >>> 0 != 1 >>> "Rajani" is "rajani" >>> "Vijay" is not "Rajani" >>> name = None >>> if name is not None: ... #do something ILUG-CBE Programming is Fun
  • 31. Boolean operators Used to combine conditional logic and or not ILUG-CBE Programming is Fun
  • 32. if ... if mark > 60 and mark < 100: print "First Class" elif mark < 60: print "Second Class Only :-(" else: print "Ooops !!!!" ILUG-CBE Programming is Fun
  • 33. if ... elif time ILUG-CBE Programming is Fun
  • 34. Sequences list List is an ordered collection of objects. names = ["rms","linus","guido","larry"] marks = [45,50,60,80,90] mixed = ["linux",12,12.35,90L] ILUG-CBE Programming is Fun
  • 35. Sequences - list names = [] print names names.append("linus") print names numbers = [6,9,2,3,1,8,4] print len(numbers) print numbers.sort() print numbers.reverse() another = [9,3,6] numbers.extend(another) print numbers numbers.insert(0,20) print numbers ILUG-CBE Programming is Fun
  • 36. Sequences - list print numbers[0] print numbers[-1] print numbers[2:-2] print numbers[:-2] print numbers[2:] print numbers[:] ILUG-CBE Programming is Fun
  • 37. Sequences -tuple tuple Tuple is like list only. But tuple is immutable nums = (1,2,3,4) print nums print len(nums) print nums[0] print nums[-1] ILUG-CBE Programming is Fun
  • 38. Sequences range nums = range(20) print nums selected = range(20,60) print selected jump2 = range(10,100,2) print jump2 ILUG-CBE Programming is Fun
  • 39. Let’s do some sequencing ILUG-CBE Programming is Fun
  • 40. Iteration names = ["linus","rms","guido","larry"] for name in names: print "hello %s" %(name) for num in range(10,20,2): print num ILUG-CBE Programming is Fun
  • 41. Iteration for i in range(len(names)): print i,names[i] for i,v in enumerate(names): print i,v ILUG-CBE Programming is Fun
  • 42. Iteration break,continue and pass for name in names: print name if name == "guido": break for name in names: print name if name == "linus": continue for name in names: print name if name == "rms": pass ILUG-CBE Programming is Fun
  • 43. Iteration - while my_number = 10 while my_number < 20: print my_number my_number += 2 ILUG-CBE Programming is Fun
  • 44. Let’s Iterate ILUG-CBE Programming is Fun
  • 45. Dictionaries Also called as hash, hashmap or associative array address = {"name":"ILUG-CBE","houseno":"Nil", "street":"any whare","city":"Coimbatore"} print address ILUG-CBE Programming is Fun
  • 46. Dictionaries address["state"] = "tamilnadu" address["web"] = "ilugcbe.org.in" print address ILUG-CBE Programming is Fun
  • 47. Dictionaries print address.has_key("country") print address.get("phone","No Phone Number Provided") ILUG-CBE Programming is Fun
  • 48. Dictionaries address.setdefault("country","India") print address print address.keys() print address.values() print address.items() del address["country"] print address ILUG-CBE Programming is Fun
  • 49. Let’s practice Dictionaries ILUG-CBE Programming is Fun
  • 50. Functions def say_hai(): print "hello" say_hai() ILUG-CBE Programming is Fun
  • 51. Functions def add_two(num): return num + 2 res = add_two(4) print res ILUG-CBE Programming is Fun
  • 52. Functions def add(a,b): """ adds two numbers """ return a + b res = add_two(4,5) print res ILUG-CBE Programming is Fun
  • 53. Functions def demo(*args): """ *args demo """ for arg in args: print i * 2 demo(1,2,3,4,5,6) ILUG-CBE Programming is Fun
  • 54. Functions def demo(num,*args): """ *args demo """ for arg in args: print i * num demo(1,2,3,4,5,6) ILUG-CBE Programming is Fun
  • 55. Functions def demo(num,*args): """ *args demo """ mul = [] for arg in args: mul.append(i * num) return sum(mul) res = demo(2,2,3,4,5,6) print res ILUG-CBE Programming is Fun
  • 56. Functions def marker(roll_no,details): if details[’marks’] > 60: print "Roll no %d %s" %(roll_no, "First Class") marker(12,marks = 62) ILUG-CBE Programming is Fun
  • 57. Functions def mulbythree(num,three=3): """ default argument example """ return num * three res = mulbythree(43) print res ILUG-CBE Programming is Fun
  • 58. Be functional now ILUG-CBE Programming is Fun
  • 59. Tricks 1 nums = [1,2,3,4,5,6,7,8,9] mulbt = [num * 2 for num in nums] print nums print mulbt ILUG-CBE Programming is Fun
  • 60. Tricks - 2 nums = [1,2,3,4,5,6,7,8,9] mulbt = [num * 2 for num in nums if num / 2 != 0] print nums print mulbt ILUG-CBE Programming is Fun
  • 61. Tricks - 3 nums = [1,2,3,4,5,6,7,8,9] numtuple = tuple(nums) print type(nums) print type(numtuple) ILUG-CBE Programming is Fun
  • 62. Tricks - 4 print "ILUGCBE".lower().upper().title() ILUG-CBE Programming is Fun
  • 63. User input name = raw_input("Tell your name: ") print name age = int(raw_input("Tell your age: ")) print age ILUG-CBE Programming is Fun
  • 64. Tricks time ILUG-CBE Programming is Fun
  • 65. Lambda product = lambda x,y : x * y res = product(12,13) print res ILUG-CBE Programming is Fun
  • 66. Lambda dbtnt = lambda x : x * 2 if x % 2 == 0 else x res = dbtnt(12) print res ILUG-CBE Programming is Fun
  • 67. Lambda bors = lambda x: x > 100 and ’big’ or ’small’ for i in (1, 10, 99, 100, 101, 110): print i, ’is’, f(i) ILUG-CBE Programming is Fun
  • 68. Object Oriented Programming - basics class MyClass: """ This is my class """ def __init__(self): #nothing def say_hai(self): print "Hai" obj = MyClass() obj.say_hai() ILUG-CBE Programming is Fun
  • 69. Object Oriented Programming - basics class MyClass(object): """ This is my class """ def __init__(self): #nothing def say_hai(self): print "Hai" obj = MyClass() obj.say_hai() ILUG-CBE Programming is Fun
  • 70. Object Oriented Programming - basics class Student: """ Student class """ def __init__(self): self.college = "My College" def greet(self,name): """ Function to greet student """ print "Hello %s from %s" %(name, self.college) student = Student() student.greet("Jaganadh") ILUG-CBE Programming is Fun
  • 71. Object Oriented Programming - inheritance class BeStudent: def __init__(self): Student.__init__(self) self.class = "BE First Year" def greet(self,name): print "Hello %s from %s %s class" %(name, self.college,self.class) student = BeStudent() student.greet("Jaganadh G") ILUG-CBE Programming is Fun
  • 72. Object Oriented Time ILUG-CBE Programming is Fun
  • 73. File I/O - read file input = open("file.txt",’r’) contents = input.read() input.close() print contents input = open("file.txt",’r’) contents = input.readlines() input.close() print contents ILUG-CBE Programming is Fun
  • 74. File I/O - write to file names = ["linus","rms","larry","guido"] output = open("out_file.txt",’w’) for name in names: output.write(name) output.write("n") ILUG-CBE Programming is Fun
  • 75. File I/O - write to file names = ["linus","rms","larry","guido"] output = open("out_file.txt",’a’) for name in names: output.write(name) output.write("n") ILUG-CBE Programming is Fun
  • 76. Let’s play with files ILUG-CBE Programming is Fun
  • 77. Batteries Standard Libraries Python comes with batteries included. Lots of useful libraries are there in the language. Let’s see some of these libraries now import math print math.pi print math.sqrt(10) print math.factorial(10) print math.sin(10) print math.pow(10,2) print math.log(10) print math.log(10,2) print math.log10(10) print math.exp(10) ILUG-CBE Programming is Fun
  • 78. Batteries - sys import sys print sys.platform afl = sys.argv[1] print sys.version print sys.maxint print sys.maxsize ILUG-CBE Programming is Fun
  • 79. Batteries - os import os print os.curdir() print os.getlogin() print os.getcwd() print os.name ILUG-CBE Programming is Fun
  • 80. Batteries - time,random import time print time.ctime() print time.gmtime() import random print random.random() print random.choice([1,2,3,4,5,6]) ILUG-CBE Programming is Fun
  • 81. Battery Recharge ILUG-CBE Programming is Fun
  • 82. Question Time ILUG-CBE Programming is Fun
  • 83. Contributors Jaganadh G @jaganadhg Biju B @bijubk Satheesh Kumar D Sreejith S @tweet2sree Rajith Ravi @chelakkandupoda ILUG-CBE Programming is Fun
  • 84. Contact US Web http://ilugcbe.org.in mail mail2ilugcbe@gmail.com ILUG-CBE Programming is Fun