SlideShare a Scribd company logo
1 of 27
An Introduction to Python




     SNAKES ON THE WEB:- Python

            Sumit Kumar Raj
Contents

●   What is Python ???
●   Why Python ???
●   Who uses Python ???
●   Running Python
●   Syntax Walkthroughs
●   Python Twitter API
●   Coding Mantras
What is Python ???



   General purpose, object-oriented, high level
    programming language
   Widely used in the industry
   Used in web programming and in standalone
    applications
History

●   Created by Guido von Rossum in 1990 (BDFL)
●   Named after Monty Python's Flying Circus
●   http://www.python.org/~guido/
●   Blog http://neopythonic.blogspot.com/
●   Now works for Dropbox
Why Python ???

●   Readability, maintainability, very clear readable syntax
●   Fast development and all just works the first time...
●   very high level dynamic data types
●   Automatic memory management
●   Free and open source
     ●   Implemented under an open source license. Freely usable
         and distributable, even for commercial use.
●   Simplicity, Availability (cross-platform), Interactivity (interpreted
    language)
●   Get a good salaried Job
Batteries Included

●   The Python standard library is very extensive
     ●   regular expressions, codecs
     ●   date and time, collections, theads and mutexs
     ●   OS and shell level functions (mv, rm, ls)
     ●   Support for SQLite and Berkley databases
     ●   zlib, gzip, bz2, tarfile, csv, xml, md5, sha
     ●   logging, subprocess, email, json
     ●   httplib, imaplib, nntplib, smtplib
     ●   and much, much more ...
Who uses Python ???
Hello World

 In addition to being a programming language, Python is also an
 interpreter. The interpreter reads other Python programs and
 commands, and executes them


Lets write our first Python Program

  print “Hello World!”
Python is simple


print "Hello World!"                           Python
#include <iostream.h>

                                               C++
int main()
{
cout << "Hello World!";
}

public class helloWorld
{
     public static void main(String [] args)   Java
     {
     System.out.println("Hello World!");
     }
}
Let's dive into some code

                          Variables and types
>>> a = 'Hello world!'       # this is an assignment statement
>>> print a
'Hello world!'
>>> type(a)                  # expression: outputs the value in interactive mode
<type 'str'>


    •   Variables are created when they are assigned
    •   No declaration required
    •   The variable name is case sensitive: ‘val’ is not the same as ‘Val’
    •   The type of the variable is determined by Python
    •   A variable can be reassigned to whatever, whenever

>>> n = 12                                    >>> n = 'apa'
>>> print n                                   >>> print n
12                                            'apa'
>>> type(n)                                   >>> type(n)
<type 'int'>                                  <type 'str'>

>>> n = 12.0
>>> type(n)
<type 'float'>
Strings: format()

>>>age = 22
>>>name = 'Sumit'
>>>len(name)
>>>print “I am %s and I have owned %d cars” %(“sumit”, 3)
I am sumit I have owned 3 cars
>>> name = name + ”Raj”
>>> 3*name
>>>name[:]
Do it !

   Write a Python program to assign your USN
    and Name to variables and print them.
   Print your name and house number using
    print formatting string “I am %s, and my
    house address number is %d” and a tuple
Strings...


 >>> string.lower()
 >>> string.upper()
 >>> string[start:end:stride]
 >>> S = ‘hello world’
 >>> S[0] = ‘h’
 >>> S[1] = ‘e’
 >>> S[-1] = ‘d’
 >>> S[1:3] = ‘el’
 >>> S[:-2] = ‘hello wor’
 >>> S[2:] = ‘llo world’
Do it...

  1) Create a variable that has your first and last name
  2) Print out the first letter of your first name
  3) Using splicing, extract your last name from the variable and
      assign it to another
  4) Try to set the first letter of your name to lowercase - what
      happens? Why?
  5) Have Python print out the length of your name string, hint
      use len()
Indentation

●    Python uses whitespace to determine blocks of code
    def greet(person):
      if person == “Tim”:
          print (“Hello Master”)
      else:
          print (“Hello {name}”.format(name=person))
Control Flow

if guess == number:           while True:
  #do something                  #do something
                                 #break when done
elif guess < number:            break
                              else:
  #do something else
                                #do something when the loop ends
else:
  #do something else

for i in range(1, 5):                for i in range(1, 5,2):
   print(i)                             print(i)
else:                                else:
   print('The for loop is over')        print('The for loop is over')
#1,2,3,4                             #1,3
Data Structures

●   List
     ●   Mutable data type, array-like
     ●   [1, 2, 4, “Hello”, False]
     ●   list.sort() ,list.append() ,len(list), list[i]
●   Tuple
     ●   Immutable data type, faster than lists
     ●   (1, 2, 3, “Hello”, False)
●   Dictionary
     ●   {42: “The answer”, “key”: “value”}
Functions


    def sayHello():
       print('Hello World!')
●   Order is important unless using the name
    def foo(name, age, address) :
        pass

    foo('Tim', address='Home', age=36)
●   Default arguments are supported
    def greet(name='World')
Functions

def printMax(x, y):
  '''Prints the maximum of two numbers.
  The two values must be integers.'''
  x = int(x) # convert to integers, if possible
  y = int(y)
  if x > y:
     return x
  else:
     return y
printMax(3, 5)
Input & Output

 #input
 something = input('Enter text: ')

 #output
 print(something)
Files

myString = ”This is a test string”
f = open('test.txt', 'w') # open for 'w'riting
f.write(myString) # write text to file
f.close() # close the file
f = open('test.txt') #read mode
while True:
  line = f.readline()
  if len(line) == 0: # Zero length indicates EOF
     break
  print(line, end='')
f.close() # close the file
Linux and Python




     ”Talk is cheap. Show me the code.”
                Linus Torvalds
A small code to get tweets ...


 from twython import Twython
 twitter = Twython()
 # First, let's grab a user's timeline. Use the 'screen_name'
 parameter with a Twitter user name.
 user_timeline =
 twitter.getUserTimeline(screen_name="sumit12dec",)
 #count=100, include_rts=1

 for tweet in user_timeline:
   print tweet["text"]
More Resources


●   http://www.python.org/doc/faq/
●   http://www.codecademy.com/tracks/python
●   http://codingbat.com/python
●   http://www.tutorialspoint.com/python/index.htm
●   How to Think Like a Computer Scientist, Learning with Python
    Allen Downey, Jeffrey Elkner, Chris Meyers
●   Google
Coding Mantras

   InterviewStreet
   ProjectEuler
   GSoC
   BangPypers
   Open Source Projects
Any Questions ???
Thank You
Reach me @:
facebook.com/sumit12dec

sumit786raj@gmail.com

9590 285 524

More Related Content

What's hot

Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Programming in Python
Programming in Python Programming in Python
Programming in Python Tiji Thomas
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administrationvceder
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...Maulik Borsaniya
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAhmed Salama
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 
Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)Matt Harrison
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basicsLuigi De Russis
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasserySHAMJITH KM
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 

What's hot (20)

Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 
Python
PythonPython
Python
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Python language data types
Python language data typesPython language data types
Python language data types
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Python for Beginners(v1)
Python for Beginners(v1)Python for Beginners(v1)
Python for Beginners(v1)
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python basic
Python basicPython basic
Python basic
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 

Similar to An Intro to Python in 30 minutes

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
 
Lesson1 python an introduction
Lesson1 python an introductionLesson1 python an introduction
Lesson1 python an introductionArulalan T
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptJoshCasas1
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.pptVicVic56
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptUdhayaKumar175069
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in Cummeafruz
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functionsray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptAlefya1
 
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
 

Similar to An Intro to Python in 30 minutes (20)

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...
 
Lesson1 python an introduction
Lesson1 python an introductionLesson1 python an introduction
Lesson1 python an introduction
 
Python
PythonPython
Python
 
Python intro
Python introPython intro
Python intro
 
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
 
python.pdf
python.pdfpython.pdf
python.pdf
 
Python basics
Python basicsPython basics
Python basics
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
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
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Python
PythonPython
Python
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 

Recently uploaded

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
"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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
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
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 

Recently uploaded (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
"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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
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
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
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?
 

An Intro to Python in 30 minutes

  • 1. An Introduction to Python SNAKES ON THE WEB:- Python Sumit Kumar Raj
  • 2. Contents ● What is Python ??? ● Why Python ??? ● Who uses Python ??? ● Running Python ● Syntax Walkthroughs ● Python Twitter API ● Coding Mantras
  • 3. What is Python ???  General purpose, object-oriented, high level programming language  Widely used in the industry  Used in web programming and in standalone applications
  • 4. History ● Created by Guido von Rossum in 1990 (BDFL) ● Named after Monty Python's Flying Circus ● http://www.python.org/~guido/ ● Blog http://neopythonic.blogspot.com/ ● Now works for Dropbox
  • 5. Why Python ??? ● Readability, maintainability, very clear readable syntax ● Fast development and all just works the first time... ● very high level dynamic data types ● Automatic memory management ● Free and open source ● Implemented under an open source license. Freely usable and distributable, even for commercial use. ● Simplicity, Availability (cross-platform), Interactivity (interpreted language) ● Get a good salaried Job
  • 6. Batteries Included ● The Python standard library is very extensive ● regular expressions, codecs ● date and time, collections, theads and mutexs ● OS and shell level functions (mv, rm, ls) ● Support for SQLite and Berkley databases ● zlib, gzip, bz2, tarfile, csv, xml, md5, sha ● logging, subprocess, email, json ● httplib, imaplib, nntplib, smtplib ● and much, much more ...
  • 8. Hello World In addition to being a programming language, Python is also an interpreter. The interpreter reads other Python programs and commands, and executes them Lets write our first Python Program print “Hello World!”
  • 9. Python is simple print "Hello World!" Python #include <iostream.h> C++ int main() { cout << "Hello World!"; } public class helloWorld { public static void main(String [] args) Java { System.out.println("Hello World!"); } }
  • 10. Let's dive into some code Variables and types >>> a = 'Hello world!' # this is an assignment statement >>> print a 'Hello world!' >>> type(a) # expression: outputs the value in interactive mode <type 'str'> • Variables are created when they are assigned • No declaration required • The variable name is case sensitive: ‘val’ is not the same as ‘Val’ • The type of the variable is determined by Python • A variable can be reassigned to whatever, whenever >>> n = 12 >>> n = 'apa' >>> print n >>> print n 12 'apa' >>> type(n) >>> type(n) <type 'int'> <type 'str'> >>> n = 12.0 >>> type(n) <type 'float'>
  • 11. Strings: format() >>>age = 22 >>>name = 'Sumit' >>>len(name) >>>print “I am %s and I have owned %d cars” %(“sumit”, 3) I am sumit I have owned 3 cars >>> name = name + ”Raj” >>> 3*name >>>name[:]
  • 12. Do it !  Write a Python program to assign your USN and Name to variables and print them.  Print your name and house number using print formatting string “I am %s, and my house address number is %d” and a tuple
  • 13. Strings... >>> string.lower() >>> string.upper() >>> string[start:end:stride] >>> S = ‘hello world’ >>> S[0] = ‘h’ >>> S[1] = ‘e’ >>> S[-1] = ‘d’ >>> S[1:3] = ‘el’ >>> S[:-2] = ‘hello wor’ >>> S[2:] = ‘llo world’
  • 14. Do it... 1) Create a variable that has your first and last name 2) Print out the first letter of your first name 3) Using splicing, extract your last name from the variable and assign it to another 4) Try to set the first letter of your name to lowercase - what happens? Why? 5) Have Python print out the length of your name string, hint use len()
  • 15. Indentation ● Python uses whitespace to determine blocks of code def greet(person): if person == “Tim”: print (“Hello Master”) else: print (“Hello {name}”.format(name=person))
  • 16. Control Flow if guess == number: while True: #do something #do something #break when done elif guess < number: break else: #do something else #do something when the loop ends else: #do something else for i in range(1, 5): for i in range(1, 5,2): print(i) print(i) else: else: print('The for loop is over') print('The for loop is over') #1,2,3,4 #1,3
  • 17. Data Structures ● List ● Mutable data type, array-like ● [1, 2, 4, “Hello”, False] ● list.sort() ,list.append() ,len(list), list[i] ● Tuple ● Immutable data type, faster than lists ● (1, 2, 3, “Hello”, False) ● Dictionary ● {42: “The answer”, “key”: “value”}
  • 18. Functions def sayHello(): print('Hello World!') ● Order is important unless using the name def foo(name, age, address) : pass foo('Tim', address='Home', age=36) ● Default arguments are supported def greet(name='World')
  • 19. Functions def printMax(x, y): '''Prints the maximum of two numbers. The two values must be integers.''' x = int(x) # convert to integers, if possible y = int(y) if x > y: return x else: return y printMax(3, 5)
  • 20. Input & Output #input something = input('Enter text: ') #output print(something)
  • 21. Files myString = ”This is a test string” f = open('test.txt', 'w') # open for 'w'riting f.write(myString) # write text to file f.close() # close the file f = open('test.txt') #read mode while True: line = f.readline() if len(line) == 0: # Zero length indicates EOF break print(line, end='') f.close() # close the file
  • 22. Linux and Python ”Talk is cheap. Show me the code.” Linus Torvalds
  • 23. A small code to get tweets ... from twython import Twython twitter = Twython() # First, let's grab a user's timeline. Use the 'screen_name' parameter with a Twitter user name. user_timeline = twitter.getUserTimeline(screen_name="sumit12dec",) #count=100, include_rts=1 for tweet in user_timeline: print tweet["text"]
  • 24. More Resources ● http://www.python.org/doc/faq/ ● http://www.codecademy.com/tracks/python ● http://codingbat.com/python ● http://www.tutorialspoint.com/python/index.htm ● How to Think Like a Computer Scientist, Learning with Python Allen Downey, Jeffrey Elkner, Chris Meyers ● Google
  • 25. Coding Mantras  InterviewStreet  ProjectEuler  GSoC  BangPypers  Open Source Projects
  • 27. Thank You Reach me @: facebook.com/sumit12dec sumit786raj@gmail.com 9590 285 524

Editor's Notes

  1. - needs Software Freedom Day@Alexandria University
  2. Write most useful links for beginners starting
  3. Write something more interactive