Вы находитесь на странице: 1из 12

CS-106

Introduction to Computer Programming


with Python

SAQIB SHAHID RAHIM


Lecturer, Computing & Technology Deptt
ABASYN University Peshawar, Pakistan

1
Lecture 2

2
History Of Python
 Python was conceived in 1980s, and its implementation began in
December 1989 by Guido van Rossum at Centrum Wiskunde &
Informatica (CWI) in the Netherlands as a successor to the ABC
language.

 In December 1989, he was looking for a "hobby" programming project


that would keep him occupied during the week around Christmas.

 His office would be closed, but he had a home computer, and not much
else on his hands.

 He decided to write an interpreter for a new scripting language.

 He chose Python as a working title for the project, being in a slightly


irreverent mood (and a big fan of Monty Python's Flying Circus) 3
Python
 Python is a general-purpose, interpreted, object-oriented
programming language.

 Python was created by Guido van Rossum in the Netherlands in 1990


and was named after the popular British comedy troupe Monty
Python’s Flying Circus.

 Van Rossum developed Python as a hobby, and Python has become a


popular programming language widely used in industry and academia
due to its simple, concise syntax and extensive library.

 Python is now used in the Google search engine, in mission-critical


projects at NASA, and in transaction processing at the New York
Stock Exchange.
4
Versions of Python
 Python is now being developed and maintained by a large team of
volunteers and is available for free from the Python Software
Foundation.

 Two versions of Python are currently coexistent:


 Python 2 and Python 3

 Python 2.0 was released on 16 October 2000 and had many major new
features, including a garbage collector and support for Unicode.

 Python 3.0 (which early in its development was commonly referred to


as Python 3000 or py3k), a major, backwards-incompatible release,
was released on 3 December 2008 after a long period of testing.

5
Versions of Python
 The programs written in Python 3 will not run in Python2.

 Python 3 is a newer version, but it is not backward-compatible with


Python 2.

 Python provides a tool that automatically converts code written in


Python 2 into syntax Python 3 can use.

Note:
 We will learn programming using Python 3 in our course

6
Python Programming Modes
 Both the command-line Python interpreter and IDLE are available after Python is
installed on your machine.

 Python’s IDLE provides two modes to work:

1. Python Programming in Interactive Mode


An interpreter can immediately execute instructions as they are
entered. This is referred to as interactive mode . It is a very
useful feature for program development. In this mode, you can tell
Python what to do and it’ll respond immediately. Using the
interactive mode gives you immediate feedback. But it’s
not designed to create programs you can save and run later.

2. Python Programming in Script Mode:


Python’s IDLE also offers a script mode, in which you can write,
edit, load, and save your programs. It’s like a word processor for
your code. You can perform such as find, cut, paste, etc
7
Python Programming Modes
 Interactive mode is great for trying out a small idea quickly.

 The interactive window is like a scratch pad where we can experiment.

 Script mode is perfect for writing programs you can run later.

 Even though we need only script mode to write a program but always keep an
interactive window open.

 Using both modes together is a great way to code.

 These both modes helps us to write better programs more quickly.

8
Programming Errors
1. Syntax Errors
 The most common error you will encounter are syntax errors. Like any programming

language, Python has its own syntax, and you need to write code that obeys the
syntax rules. If your program violates the rules Python will report syntax errors.
Syntax errors result from errors in code construction, such as mistyping a statement,
incorrect indentation, omitting some necessary punctuation, or using an opening
parenthesis without a corresponding closing parenthesis. These errors are usually
easy to detect, because Python tells you where they are and what caused them.

9
Programming Errors
2. Runtime Errors
 Runtime errors are errors that cause a program to terminate abnormally. They occur

while a program is running if the Python interpreter detects an operation that is


impossible to carry out. Input mistakes typically cause runtime errors. An input error
occurs when the user enters a value that the program cannot handle.

3. Logical/Sementic Errors
 Logical errors occur when a program does not perform the way it was intended to.

Errors of this kind occur for many different reasons.

10
Words
 Keywords: Keywords, also called reserved words, have special meanings in Python.
These are predefined to language translator.
 Identifiers: These are user defined words.

 Rules for Identifier:

All identifiers must obey the following rules:


1. An identifier is a sequence of characters that consists of letters, digits, and
underscores (_).
2. An identifier must start with a letter or an underscore.
3. It cannot start with a digit.
4. An identifier cannot be a keyword.
5. An identifier can be of any length.
6. An identifier should be meaningful.
7. No blank spaces
8. Must be unique
9. No special symbols
When Python detects an illegal identifier, it reports a syntax error
11
Programming Statements
 Simple Statements

 Structured Statements
1. Selection
2. Iterative
3. Compound

12

Вам также может понравиться