python programming

35
Python Programming Ameer Fazal

Upload: ameer-fazal

Post on 13-Aug-2015

126 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Python programming

Python Programming

Ameer Fazal

Page 2: Python programming

• Designed by Guido van Rossum• First appeared in 1991 • As a successor to the ABC

Language

Page 3: Python programming

Python

• Official Website – www.python.org• Distributed under FLOSS (Free/Libré and Open

Source Software)• “Sharing is Caring”

Page 4: Python programming

Named after the BBC Comedy Troupe Monty Python and the Flying Circus

Page 5: Python programming

What is Python

• General Purpose • High Level• Interpreted• Open Source Programming Language

Page 6: Python programming

Why Python• Ease of Use and Powerful• Community Driven• Currently it’s in the top eight programming

languages in the world according to TIOBE Index

• Two times winner of Programming Language of the Year(2007 and 2010) by TIOBE Index

Page 7: Python programming

Some Organizations Using Python• Google• Yahoo• Walt Disney Feature Animation• NASA• Red Hat• Nokia • IBM • CERN• Website of CIA• Quora• Instagram

Page 8: Python programming

• A ranking of the highest-paying programming languages by average salaries. (ViaQuartz)

Page 9: Python programming
Page 10: Python programming
Page 11: Python programming

Python 2 and Python 3

Python 2.x is legacyPython 3.x is the present and future of the language

In this tutorial we are using both Python 3 and Python 2

Page 12: Python programming

Installation on Windows

• Go to https://www.python.org/downloads/• Click Download Python 3.4.1 (or later) for

Windows (a .msi file)

Page 13: Python programming

Python Interpreter

Page 14: Python programming

Hello World! Program• print(‘Hello World!’)

Page 15: Python programming

Interactive Programming in the Interpreter

Page 16: Python programming

Python is Interpreted

• Python does not need compilation to binary• Python converts the source code into an

intermediate form called bytecodes• Then translates this into the native language

of your computer and then runs it

Page 17: Python programming

Python is Object Oriented

• Python supports procedure-oriented programming as well as object-oriented programming

• Python has a very powerful but simplistic way of doing OOP, especially when compared to big languages like C++ or Java.

Page 18: Python programming

Python is Simple

• Python is a simple and minimalistic language. Reading a good Python program feels almost like reading English, although very strict English!

Page 19: Python programming

Python is Easy to Learn

• As you will see, Python is extremely easy to get started with. Python has an extraordinarily simple syntax, as already mentioned

Page 20: Python programming

The Zen of PythonThe core philosophy of the language is summarized by the document "PEP 20 (The Zen of Python)", which includes aphorisms such as:• Beautiful is better than ugly • Explicit is better than implicit • Simple is better than complex • Complex is better than complicated • Readability counts

Page 21: Python programming

The Zen of Python

Page 22: Python programming

Getting Help

• You can use the built-in help functionality• E.g. help(print)

• Press q to exit the help.

Page 23: Python programming

Saving Python Programs

• Type the program in Integrated Development Environment or a Text Editor Program and save it as .py file extension

Page 24: Python programming

Comments

• Comments are ignored by Python Interpreter• # Symbol for Single Line Comments• Triple Quotes for Multi Line Comments

(“”” or ‘’’)

Code tells you how, comments should tell you why.

Page 25: Python programming

CommentsUse as many useful comments as you can in your program to:

• explain assumptions• explain important decisions• explain important details• explain problems you’re trying to solve• explain problems you’re trying to overcome

in your program, etc.

Page 26: Python programming

Literal Constants

• It is called a literal because it is literal –you use its value literally

• It is a constant because its value cannot be changed

• E.g. Numbers- 5, 1.23Strings- ‘hello’

Page 27: Python programming

Numbers• Numbers are mainly of two types - integers and

floats• Integers- Whole Numbers- e.g. 2, 3, 10, 997• Floating Point Numbers-

e.g. 3.25, 4.0

• Note for Experienced Programmers: There is no separate long type. The int type can be an integer of any size.

Page 28: Python programming

Strings• A string is a sequence of characters• Strings are basically just a bunch of words

• Single Quote - e.g. ’Quote me on this’.• Double Quotes - e.g. "What’s your name?“• Triple Quotes – Can use for strings that span on

multiple lines

e.g.'''This is a multi-line string. This is the first line. This is the second line. "What's your name?,"

I asked. He said "Bond, James Bond.“ '''

Page 29: Python programming

Strings Are Immutable

• This means that once you have created a string, you cannot change it

• You can make a new string out of an existing string

Page 30: Python programming

Raw String• If you need to specify some strings where no

special processing such as escape sequences are handled then what you need is to specify a raw string

• by prefixing r or R to the string

• Raw String and Normal String

Page 31: Python programming

Escape Sequences

• Escape Sequences use an escape character to change the meaning of the characters which follow it, meaning that the characters can be interpreted as a command rather than as data

• E.g. \t \n \’ \”

Page 32: Python programming

Variables

• Variables are always references to objects, and are never typed

• They are Case Sensitive• Variables in Python are automatically declared

by assignment

Page 33: Python programming

Identifier NamingIdentifiers are names given to identifySomething• The first character of the identifier must be a

letter of the alphabet or an underscore (‘_’)• The rest of the identifier name can consist of

letters , underscores (‘_’) or digits (0-9)• Identifier names are case-sensitive

Page 34: Python programming

How to write Python programs

1. Open your editor of choice2. Type the program code given in the example3. Save it as a file with the filename mentioned4. Run the interpreter with the command

python3 program.py (or python program.py on Windows) to run the program

Page 35: Python programming

Thanks

• Wikipedia• Python Official Website• Swaroop C H