Introduction To Python 1

Python Workshop

Introduction

  • Author - Guido van Rossum, names the language after the BBC show "Monty Python’s Flying Circus". Not after the snake.
  • simple, powerful and efficient interpreted language
  • supports object oriented programming
  • has extensive libararies for task like parsing XML, for CGI, FTP, email etc.

What is it used for?

  • rapid protootyping
  • web scripting
  • throw-away,ad hoc programming
  • scientific applications
  • XML processing database applications
  • GUI applications

Companies using Python

  • Google
  • Yahoo
  • NASA
  • Biosoft
  • Nokia
  • Vodafone
  • Red Hat
  • IBM
  • CIA
  • Walt Disney

Some commendable projects using Python

  • Bazaar and Hg Mercurial - free version control systems done in Python
  • Dropbox client - premier cloud storage provider
  • Openstack - a cloud computing IaaS platform
  • SCons - a tool for building software
  • Ubuntu Software Center - a graphical package manager
  • YUM - package management utility
  • GNU Mailman - mailing list manager

Syntax

  • comments are indicated with "#"
  • Two statements on the same line are separated with a semicolon ";"
  • No semicolon at the end of lines

High-level data types

  • Nimbers: int,long,float,complex
  • Strings and Tuples: immutable
  • Lists and dictionaries: containers
  • Other types for e.g. binary data,regular expressions,introspection
  • Extension modules can define new "built-in" data types

Built-in Data Types

Numbers

  • Integers(unlimites precision)
  • 1234,-24,0
  • Floating-Point
    • 1.23,3.14e-10,4E210,4.0e+210,1.,.1
  • Octal,hex, and binary literals for integers
    • 0o177,0x9ff,0b1111
  • Complex numbers
    • 3+4j,3.0+4.0j,3j
  • int(),float()

Strings

  • Are immutable
  • Can be written as,
    • "Python",'Python'
    • """"This is a multiline block"""
    • "' This is a multiline block" '
    • r' a raw\string'
  • s1 = 'foo' ; s2 = 'bar'; s3=s1+s2

And yes,multiple variables can be assigned like,

a,b=5, 'seven'
a,b=b,a  

String Access and slices

s='hello world' 
>>> s[0]
'h'
>>> s[-1]
'd'
>>> s[0:3]
'hel'
>>> s[3:]
'lo world'
>>> s[0:9:2]
'hlowr'
>>> 

String Operations

Command|Result

s[0] | 'h' s[-1] | 'd' s[0:3] | 'hel' s[:3] | 'hel' s[3:] | 'lo world'


blogroll