What is Python Programming Language?

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

15. Python - Modules A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Object Oriented Programming in Java George Mason University Fall 2011
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Python Henry Armstrong Andy Burras Everett Hite. History First released in 1991 by Guido van Rossum Designed around a philosophy which emphasized readability.
Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented.
Python Brandon Jeffcoat Dashaun West “Why settle for snake oil when you can have the whole snake?” -- From Usenet posting by Mark Jackson, June 1998.
Python Jordan Miller and Lauren Winkleman CS 311 Fall 2011.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
1 Python Chapter 2 © Samuel Marateck, After you install the compiler, an icon labeled IDLE (Python GUI) will appear on the screen. If you click.
CSC 9010: Natural Language Processing
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Python Introduction.
Introduction to Python Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
Ch 1. Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Python Programming Fundamentals
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
Computer Science 111 Fundamentals of Programming I Overview of Programming.
1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.
Programming language A programming language is an artificial language designed to communicate instructions to a machine,languageinstructionsmachine particularly.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
H3D API Training  Part 3.1: Python – Quick overview.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Compiling and the Java Virtual Machine (JVM). The syntax of Pseudocode is pretty loose –visual validation encourages a permissive approach –emphasized.
A very basic overview of Server-Side Scripting Or what is PHP, Perl, Python, Ruby and what can they do for me?
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Intro to Python Adriane Huber Debbie Bartlett Python Lab #1Python Lab #1 1.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Department of Electrical and Computer Engineering Introduction to C++: Primitive Data Types, Libraries and Operations By Hector M Lugo-Cordero August 27,
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Introduction to Python Origins Nature of Python Importance of Python Example.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Ch 1. A Python Q&A Session. Why do people use Python? Software Quality Developer productivity Program portability Support Libraries Component integration.
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
Fundamentals of Programming I Overview of Programming
Python Programming Unit -1.
CST 1101 Problem Solving Using Computers
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Ch 1. A Python Q&A Session Bernard Chen 2007.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Introduction to Python
Introduction to Python
PHP.
(Computer fundamental Lab)
Terminal-Based Programs
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

What is Python Programming Language? Python is a general-purpose interpreted, interactive, object-oriented and high-level programming language. It is defined as object-oriented scripting language a definition that blends support for OOPs with an over all orientation towards scripting roles. 1

What does Scripting Language mean? A scripting language is a programming language designed for integrating and communicating with other programming languages. Some of the most widely used scripting languages are JavaScript, VBScript, PHP, Perl, Python, Ruby, ASP and Tcl Scripting language is normally used in conjunction with another programming language, like HTML or Java, C++. 2

Features of Python Python is a general-purpose high-level programming language whose design philosophy emphasizes code readability. Python supports multiple programming paradigms, primarily but not limited to object oriented, imperative and, to a lesser extent, functional programming styles. Python aims to combine "remarkable power with very clear syntax", and its standard library is large and comprehensive. Its use of indentation for block delimiters is unusual among popular programming languages. 3 3

Introduction to Python Development of Python Python was developed in the late 1980s and its implementation was started in December 1989 by Guido van Rossum at CWI (Centrum Wiskunde & Informatica) in the Netherlands. 4 4

Introduction to Python Python 2.0 was released on 16 October 2000, with many major new features including a full garbage collector and support for Unicode. Python 3.0, a major, backwards-incompatible release with Python 2.x, was released on 3 December 2008 after a long period of testing. Many of its major features have been backported to the backwards-compatible Python 2.7. 5 5

4 Major Versions of Python “Python” or “CPython” is written in C/C++ - Version 2.7 came out in mid-2010 - Version 3.1.2 came out in early 2010 “Jython” is written in Java for the JVM “IronPython” is written in C# for the .Net environment 6

Technical Strengths of Python It's Object-Oriented: Python is an object-oriented language, from the ground up. Its class model supports advanced notions such as polymorphism, operator overloading, and multiple inheritance. It's Free: Python is freeware - something which has lately been come to be called open source software. It's Portable: Python is written in portable ANSI C, and compiles and runs on virtually every major platform in use today. It's Powerful: Dynamic typing, Automatic memory management, programming-in-the-large support, Built-in object types. Built-in tools, Library utilities. 7 7

Technical Strengths of Python It's Mixable: Python programs can be easily "glued" to components written in other languages. It's Easy to Use: as with other interpreted languages, Python executes programs immediately, which makes for both an interactive programming experience and rapid turnaround after program changes. 8 8

Development Environment of Python PythonWin 2.6.4 It is an interpreter which reads a high-level program and executes it, and processes the program a little at a time (statement by statement). 9 9

What can I do with Python? Python role’s are virtually unlimited: you can use it for everything from web site development and gaming to robotics and space craft control. System Programming GUIs Internet Scripting Database Programming Rapid Prototyping Numeric and Scientific Programming Natural Language Games, Images, AI, XML and more 10

Who Uses Python Today? Google and Yahoo currently use Python in Internet service Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for hardware testing. Industrial Light and Magic use Python in the production of movie animation The YouTube video sharing service is largely written in Python. The NSA uses Python for cryptography and intelligence analysis. (Web) Applications• Google PageRank algorithm and Interfaces to the Google API For more details, visit www.python.org 11

Comparison with other languages C Program Java Program Python Program main() { printf("hello, world\n"); } class myfirstjavaprog public static void main(String args[]) System.out.println("Hello World!"); print (“Hello World!!”) 12

Comparing Python to Other Languages Java : Python programs are generally expected to run slower than Java programs, but they also take much less time to develop. Python programs are typically 3-5 times shorter than equivalent Java programs. This difference can be attributed to Python's built-in high-level data types and its dynamic typing. For example, a Python programmer wastes no time declaring the types of arguments or variables, and Python's powerful polymorphic list and dictionary types, for which rich syntactic support is built straight into the language, find a use in almost every Python program.  13

Comparing Python to Other Languages Javascript Python's "object-based" subset is roughly equivalent to JavaScript. Like JavaScript (and unlike Java), Python supports a programming style that uses simple functions and variables without engaging in class definitions. However, for JavaScript, that's all there is. Python, on the other hand, supports writing much larger programs and better code reuse through a true object-oriented programming style, where classes and inheritance play an important role. 14

Comparing Python to Other Languages Perl Python and Perl come from a similar background (Unix scripting) and sport many similar features, but have a different philosophy. Perl emphasizes support for common application-oriented tasks, e.g. by having built-in regular expressions, file scanning and report generating features. Python emphasizes support for common programming methodologies such as data structure design and object-oriented programming, and encourages programmers to write readable (and thus maintainable) code by providing an elegant but not overly cryptic notation. As a consequence, Python comes close to Perl but rarely beats it in its original application domain. 15

First Python Program 16

Python Basics Built-in data structures Numbers • decimal e.g. 631, 3.14 • octal e.g. O631 • hexadecimal e.g. oxABC • complex e.g. 1 + 3j • long e.g. 122233445656455L • Normal Arithmetic and Bit operators • Integer division truncates e.g. 1/2 = 0 int(x) converts x to an integer :e.g int(2.0)=2 float(x) converts x to a floating point e.g float(2) = 2.0 17

Numbers Numbers are immutable Many math functions in the math module Complex Built into Python Same operations are supported as integer and float >>> x = 3 + 2j >>> y = -1j >>> x + y (3+1j) >>> x * y (2-3j) >>> import math >>> dir(math) ['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'] >>> 18

Python Basics Strings Strings are immutable There is no char type like in C++ or Java • Concatenation Hello” + “World” -> “HelloWorld” • Repetition “UMBC” * 3 -> “UMBCUMBCUMBC” • Indexing : “UMBC”[0] -> “U” • Slicing : “UMBC”[1:3] -> “MB” • Size : len(“UMBC”) -> 4 19

Python Basics Comparison : “UMBC” < “umbc” -> 0 • Search : “M” in “UMBC” -> 1 Can also be enclosed in single quotese.g. ‘UMBC’ Can use single or double quotes, and three double quotes for a multi-line string >>> 'I am a string' 'I am a string' >>> "So am I!" 'So am I!' >>> """And me too! ... though I am much longer ... than the others :)""" 'And me too!\nthough I am much longer\nthan the others :)' 20

The String Data Type H e l o B b 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 >>> greet = "Hello Bob" >>> greet[0] 'H' >>> print(greet[0], greet[2], greet[4]) H l o >>> x = 8 >>> print(greet[x - 2]) B

Python program structure The ‘#’ starts a line comment Variables Are not declared, just assigned The variable is created the first time you assign it a value Are references to objects Type information is with the object, not the reference Everything in Python is an object 22

Whitespace Whitespace is meaningful in Python: especially indentation and placement of newlines. Use a newline to end a line of code. (Not a semicolon like in C++ or Java.) (Use \ when must go to next line prematurely.) No braces { } to mark blocks of code in Python… Use consistent indentation instead. The first line with a new indentation is considered outside of the block. Often a colon appears at the start of a new block. (We’ll see this later for function and class definitions.)

Look at a sample of code… x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print y

Python program hello.py #!/usr/bin/python # This program says hello and asks for your name. hello = 'Hello world! ' print(hello) print('What is your name?') myName = raw_input() print('It is good to meet you, ' + myName) Steps to to compile $python hello.py or $chmod 700 hello.py ./hello.py 25

#!//usr/bin/python versus #!/usr/bin/env python #!/usr/local/bin/python You are specifying the location to the python executable in your machine, that rest of the script needs to be interpreted with. You are pointing to python is located at /usr/local/bin/python Consider the possibilities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, the above #! will fail. For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly. Thus, #/usr/bin/env python Will figure out the correct location of python ( /usr/bin/python or /bin/python from $PATH) and make that as the interpreter for rest of the script. - ( env is almost always located in /usr/bin/ so one need not worry what is env is not present at /usr/bin)

Example Program to check whether a string is palindrome or not s="abcba" mylen=len(s) for char in range(0,mylen): if (s[char] != s[(mylen-1-char)]): print ("not a plaindrome") break else: print("palindrome")

Summary Python is a general-purpose high-level programming language Python supports multiple programming paradigms, primarily but not limited to object oriented, imperative, and functional programming styles Python aims to combine "remarkable power with very clear syntax", and its standard library is large and comprehensive.

Summary Its use of indentation for block delimiters is unusual among popular programming languages. Python was conceived in the late 1980s and its implementation was started in December 1989 by Guido van Rossum at CWI in the Netherlands. Python’s advantages include object-oriented, free, portable, powerful, mixable, easy to use, and easy to learn properties. PythonWin 2.6.4 is a perfect development environment for Python under Windows. 29 29

Write a python program to add number (take input from the user) Exercises Write a python program to add number (take input from the user) Write a python program to concatenate string and integer Write a python program that asks the user how many coins of various types they have, and then prints the total amount of money in rupees. 30 30

http://172.1.2.200:81/python