240 likes | 428 Views
Python – Part 1. Python Programming Language. What is Python? . High-level language Interpreted – easy to test and use interactively Object-oriented Open-source software. What is Python?. Small, simple language Extensible – set of modules as tools to build on the language
E N D
Python – Part 1 Python Programming Language
What is Python? • High-level language • Interpreted – easy to test and use interactively • Object-oriented • Open-source software Prepared by Department of Preparatory year
What is Python? • Small, simple language • Extensible – set of modules as tools to build on the language • Familiar – features from other languages (Java, C, Perl) Prepared by Department of Preparatory year
Benefits • Consistency – maintained by a large organization of people • Scalability – Python projects scale to very large projects • Flexibility – use of libraries and programs written in other languages Prepared by Department of Preparatory year
Benefits • Interactive interpreter • Cross-platform • Easy to implement Prepared by Department of Preparatory year
Resources • Python: http://www.python.org • Installing Python: http://www.python.org/download • Python Documentation: http://docs.python.org Prepared by Department of Preparatory year
Resources • Python.org's list of editors and IDEs • http://wiki.python.org/moin/PythonEditors • http://wiki.python.org/moin/IntegratedDevelopmentEnvironments • Think Python • http://www.greenteapress.com/thinkpython/thinkpython.html Prepared by Department of Preparatory year
Python Programs • Executed by an interpreter • Two ways to use interpreter • Interactive mode • Script mode Prepared by Department of Preparatory year
Interactive Mode • >>> 1 + 1 • 2 • >>> is the prompt the interpreter uses to indicate that it is ready. • If you type 1 + 1, the interpreter replies 2. Prepared by Department of Preparatory year
Script Mode • Store code in a file • Use the interpreter to execute the contents of the file (called script, .py extention) Prepared by Department of Preparatory year
Programs • A program is a sequence of instructions that specifies how to perform a computation. • input: • Get data from the keyboard, a file, or some other device. • output: • Display data on the screen or send data to a file or other device. Prepared by Department of Preparatory year
Programs (cont…) • math: • Perform basic mathematical operations like addition and multiplication. • conditional execution: • Check for certain conditions and execute the appropriate sequence of statements. • repetition: • Perform some action repeatedly, usually with some variation. Prepared by Department of Preparatory year
Debugging • Programming errors are called bugs • Debugging - the process of tracking them down. • Three kinds of errors: • syntax errors • runtime errors • semantic errors Prepared by Department of Preparatory year
Syntax errors • Occur if syntax is not correct • Syntax refers to the structure of a program and the rules about that structure. • (1 + 2) is legal • 8) is a syntax error Prepared by Department of Preparatory year
Runtime errors • Error does not appear until after the program has started running • Also called exceptions • Rare in simple programs Prepared by Department of Preparatory year
Semantic errors • Program runs successfully (no error messages generated) • Will not do the right thing • The meaning of the program (its semantics) is wrong. • Tricky to indentify Prepared by Department of Preparatory year
The first program • Hello World program • print (‘Hello, World!’) • Print statement • Display on the screen: • Hello World Prepared by Department of Preparatory year
Exercise • Start the Python interpreter and use it as a calculator. • The symbol for multiplication is *. • If you run a 10 kilometer race in 43 minutes 30 seconds, what is your average time per mile? What is your average speed in miles per hour? (Hint: there are 1.61 kilometers in a mile). Prepared by Department of Preparatory year
Part 1 References http://www.greenteapress.com/thinkpython/thinkpython.html