PYTHON

SHIVAM K. VERMA
Python is Interpreted.
Python is Interactive.
Python is Object-Oriented.
Python is Beginner’s Language.
HISTORY
• Python was developed by Guido van Rossum in the late
80s to earlier 90s at the National Research Institute.
• Py...
FEATURES
• Broad Standard Library.

• Portable.
• Extendable.
• Databases.
• Interactive Mode.
• Scalable.
• Integration.
HOW TO GET PYTHON
The most up-to-date and current source code, binaries,
documentation, news, etc. is available at the off...
RUNNING PYTHON
• There are 3 ways to start python:
1.

Interactive Interpreter.

2.

Script from the command line.

3.

In...
INTERACTIVE INTERPRETER

SCRIPT FROM COMMAND LINE
• Unix – IDLE is the very first Unix
IDE for Python.
• Windows – Pythonwin is the first
Windows Interface for Python
and i...
PROGRAM COMPONENTS
• Programs can read in data.
• Programs can write results.
• In between reading and writing, programs c...
DOING SIMPLE ARITHIMETIC
• Here are the arithmetic operators:
• + performs addition
• - performs subtraction
• * performs ...
DECISION AND TESTS
• Your program can decide what to do by making a test
• The result of a test is a boolean value, True o...
COMPOUND TESTS
• Boolean values can be combined with these operators:
•
•
•

and – gives True if both sides are True
or – ...
THE if STATEMENT
• The if statement evaluates a test, and if it is True, performs the
following indented statements; but i...
if WITH else
• The if statement can have an optional else part, to be performed
if the test result is False
• Example:
•

...
if WITH elif
• The if statement can have any number of elif tests
• Only one group of statements is executed—those control...
INDENTATION
• Indentation is required and must be consistent
• Standard indentation is 4 spaces or one tab
• IDLE does thi...
Lists AND ranges
• A list is a sequence of values enclosed in brackets
•

Example: courses = ['CIT 591', 'CIT 592', 'CIT 5...
THE for LOOP
• A for loop performs the same statements for each value in a list
•

Example:
for n in range(1, 4):
print "T...
SUMMARY
• Arithmetic: + - * / %

< <= == != >= >

• Logic (boolean): True False and or not
• Strings: "Double quoted" or '...
Queries ?
T
H
A
N
K
Y
O
U
Python
Python
Python
Python
Upcoming SlideShare
Loading in …5
×

Python

440 views
309 views

Published on

This is a python presentation, and hoping that it will help you to understand python

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
440
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Python

  1. 1. PYTHON SHIVAM K. VERMA
  2. 2. Python is Interpreted. Python is Interactive. Python is Object-Oriented. Python is Beginner’s Language.
  3. 3. HISTORY • Python was developed by Guido van Rossum in the late 80s to earlier 90s at the National Research Institute. • Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-68, SmallTalk and Unix shell. • Python is copyrighted. Like Perl, Python source code is now available under the GNU General Public License. • Python is now maintained by a core development team at the institute, although Guido van Rossum still directing its progress.
  4. 4. FEATURES • Broad Standard Library. • Portable. • Extendable. • Databases. • Interactive Mode. • Scalable. • Integration.
  5. 5. HOW TO GET PYTHON The most up-to-date and current source code, binaries, documentation, news, etc. is available at the official website of Python: Python Official Website : http://www.python.org/ To Download : http://www.python.org/download/
  6. 6. RUNNING PYTHON • There are 3 ways to start python: 1. Interactive Interpreter. 2. Script from the command line. 3. Integrated development Environment.
  7. 7. INTERACTIVE INTERPRETER SCRIPT FROM COMMAND LINE
  8. 8. • Unix – IDLE is the very first Unix IDE for Python. • Windows – Pythonwin is the first Windows Interface for Python and is an IDE with a GUI. • Macintosh – The Macintosh version of Python along with the IDLE IDE is available.
  9. 9. PROGRAM COMPONENTS • Programs can read in data. • Programs can write results. • In between reading and writing, programs can compute, that is, do arithmetic (or logic). • test, that is, decide what to do next. • loop, that is, do the same actions a number of times. • delegate, that is, ask other parts of the program to perform some task. • • Also, programs can ignore comments.
  10. 10. DOING SIMPLE ARITHIMETIC • Here are the arithmetic operators: • + performs addition • - performs subtraction • * performs multiplication • / performs division • When dividing two integers, the result is an integer: 14 / 5 is 2 • % performs modulus (remainder of division): 14 % 5 is 4 • ** performs exponentiation • The result of doing arithmetic is often assigned to a variable: sum = 10 + 22 + 13 + 44 + 72 • Variables can be used in arithmetic: average = sum / 5
  11. 11. DECISION AND TESTS • Your program can decide what to do by making a test • The result of a test is a boolean value, True or False • Here are tests on numbers: • • • • • • < means “is less than” <= means “is less than or equal to” == means “is equal to” != means “is not equal to” >= means “is greater than or equal to” < means “is greater than” • These same tests work on strings • All capital letters are “less than” all lowercase letters.
  12. 12. COMPOUND TESTS • Boolean values can be combined with these operators: • • • and – gives True if both sides are True or – gives True if at least one side is True not – given True, this returns False, and vice versa • Examples • • score > 0 and score <= 100 name == “Abhi" and not score > 100
  13. 13. THE if STATEMENT • The if statement evaluates a test, and if it is True, performs the following indented statements; but if the test is False, it does nothing • Examples: • • if grade == "A+": print "Congratulations!" if score < 0 or score > 100: print "That’s not possible!" score = input("Enter a correct value: ")
  14. 14. if WITH else • The if statement can have an optional else part, to be performed if the test result is False • Example: • if grade == "A+": print "Congratulations!" else: print "You could do so much better." print "Your mother will be disappointed."
  15. 15. if WITH elif • The if statement can have any number of elif tests • Only one group of statements is executed—those controlled by the first test that passes • Example: • if grade == "A": print "Congratulations!" elif grade == "B": print "That's pretty good." elif grade == "C": print "Well, it's passing, anyway." else: print "You really blew it this time!"
  16. 16. INDENTATION • Indentation is required and must be consistent • Standard indentation is 4 spaces or one tab • IDLE does this pretty much automatically for you • Example: • if 2 + 2 != 4: print "Oh, no!" print "Arithmethic doesn't work!" print "Time to buy a new computer."
  17. 17. Lists AND ranges • A list is a sequence of values enclosed in brackets • Example: courses = ['CIT 591', 'CIT 592', 'CIT 593'] • You can refer to an individual value by putting a bracketed number (starting from 0) after the list • Example: courses[2] is 'CIT 593' • The len function tells you how many things are in a list • Example: len(courses) is 3 • range is a function that creates a list of integers, from the first number up to but not including the second number • Example: range(0, 5) creates the list [0, 1, 2, 3, 4] • If you give range a third number, it is used as the step size • Example: range(2, 10, 3) creates the list [2, 5, 8]
  18. 18. THE for LOOP • A for loop performs the same statements for each value in a list • Example: for n in range(1, 4): print "This is the number", n prints This is the number 1 This is the number 2 This is the number 3 • The for loop uses a variable (in this case, n) to hold the current value in the list
  19. 19. SUMMARY • Arithmetic: + - * / % < <= == != >= > • Logic (boolean): True False and or not • Strings: "Double quoted" or 'Single quoted' • Lists: [1, 2, 3, 4] len(lst) • Input: input(question) range(0, 100, 5) raw_input(question) • Decide: if test: elif test: else: • For loop: for variable in list: • While loop: while test: • Calling a function: sum(numbers) • Defining a function: def sum(numbers): return result
  20. 20. Queries ?
  21. 21. T H A N K Y O U

×