python programming
TRANSCRIPT
Python Programming
Ameer Fazal
• Designed by Guido van Rossum• First appeared in 1991 • As a successor to the ABC
Language
Python
• Official Website – www.python.org• Distributed under FLOSS (Free/Libré and Open
Source Software)• “Sharing is Caring”
Named after the BBC Comedy Troupe Monty Python and the Flying Circus
What is Python
• General Purpose • High Level• Interpreted• Open Source Programming Language
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
Some Organizations Using Python• Google• Yahoo• Walt Disney Feature Animation• NASA• Red Hat• Nokia • IBM • CERN• Website of CIA• Quora• Instagram
• A ranking of the highest-paying programming languages by average salaries. (ViaQuartz)
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
Installation on Windows
• Go to https://www.python.org/downloads/• Click Download Python 3.4.1 (or later) for
Windows (a .msi file)
Python Interpreter
Hello World! Program• print(‘Hello World!’)
Interactive Programming in the Interpreter
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
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.
Python is Simple
• Python is a simple and minimalistic language. Reading a good Python program feels almost like reading English, although very strict English!
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
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
The Zen of Python
Getting Help
• You can use the built-in help functionality• E.g. help(print)
• Press q to exit the help.
Saving Python Programs
• Type the program in Integrated Development Environment or a Text Editor Program and save it as .py file extension
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.
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.
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’
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.
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.“ '''
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
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
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 \’ \”
Variables
• Variables are always references to objects, and are never typed
• They are Case Sensitive• Variables in Python are automatically declared
by assignment
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
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
Thanks
• Wikipedia• Python Official Website• Swaroop C H