Introduction To Python
Introduction To Python
INTRODUCTION
• An ordered set of instructions to be executed by a computer to carry out a specific
task is called a program
• A Programming language is a set of instruction written in specific language (C,
C++, Java, Python)
• A programming language is a computer language that is used to communicate with
computers.
• The program which is translated into machine readable form is known as object code.
• Python uses interpreter to convert its instructions into machine language.
• An interpreter processes the program statements one by one , first translating
and then
• executing.
HISTORY OF PYTHON
• The programming language python was conceived in the late 1980’s by GUIDO
VAN ROSSUM at CENTRAM WISKUNDE AND INFORMATION (CWI) in
Netherlands as a successor to the ABC programming language.
• Python programming implementation was started in December 1989.
FEATURES OF PYTHON
✓ Python is high-level language. It is free and open source language
✓ It is an interpreted language.
✓ as python programs are executed by an interpreter.
✓ Python programs are easy to understand
as they have clearly defined syntax and simple structure
✓ Python is case-sensitive
for eg: NUM and num are not same in python
✓ Python is portable and platform independent language
means it can run on various operating system and hardware platform
( o/s linux, windows, macos)
✓ Python has a rich library of predefined functions
✓ Python is helpful in web-development. Many web services and applications are built
using python.
✓ Python uses indentation for blocks and nested blocks.
APPLICATIONS
SCRIPT MODE
❖ Script mode allows us to write more than one instruction in a file.
❖ It is called python source code which can be executed
❖ Python programs are saved as files and filename has .py as extension
❖ In script mode after saving the file, we have to click Run->module from the menu.
❖ The output appears on the shell.
❖ Script mode is useful for creating program and then run the programs later
❖ Popular python IDE’s are
❖ Python IDLE, Spyder IDE, Jupyter Notes, Pycharam IDE
TOKENS
➢ The smallest individual unit in a program is known as Token or
LEXICAL UNIT.
Eg: Text, individual words and punctuation marks.
Python has following tokens
KEYWORDS
➢ Keywords are RESERVED WORDS
➢ Keywords are the words that has a specific meaning and purposes to the
python interpreter.
➢ Keywords cannot be used as normal identifier names
➢ Python is case-sensitive.
➢ List of all keywords in Python Programming
IDENTIFIERS
Identifiers are names used to identify variables, objects, classes , functions, lists,
dictionaries etc.
Rules for writing identifiers
• It can be of any length (it is an long sequence of letters and digits)
• The first character must be letter (either uppercase or lowercase), the
underscore ( _ )
• It cannot start with digit
• It should not be a keyword or reserved word
• Python is case sensitive, it treats uppercase and lowercase differently
• We cannot use special symbols except underscore. (@,!,#.......)
VARIABLES
• Variables are named labels, whose values can be used and processed
during program run.
• Variables refers to an object in python. i.e. an element that is stored in
memory.
• Value of the variable can be string, numeric or any combination of
alphanumeric characters.
Rules
• A variable name must start with a letter or underscore character
• It cannot start with a number
• It can only contain alpha-numeric character and underscore
• They are case-sensitive.
• Cannot use keywords as variables.
Lvalue = Rvalue eg: marks= 20*30+50/10
(object) = (literals and expressions)
Note: variables in python do not have fixed locations. The location changes
every time their values change.
• Variable declaration is implicit, means the variables are declared and
defined automatically when they are assigned a value.
• Assignment statement can be used to create new variable and assign
specific values.
• Variables must always be assigned values before they are used in the
expression, the interpreter replaces it with the value of that particular
variable