0% found this document useful (0 votes)
73 views

Introduction To Python

Python is an interpreted, interactive, object-oriented programming language that is easy to learn and maintain. It can be used to create a wide range of applications and is free and open source. Python code is executed line by line by an interpreter. Programs can be run interactively or saved as scripts. Python supports key data types like numbers, strings, lists, and tuples. Strings are sequences of characters that can be accessed using indexing and slicing.

Uploaded by

DamnBJ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Introduction To Python

Python is an interpreted, interactive, object-oriented programming language that is easy to learn and maintain. It can be used to create a wide range of applications and is free and open source. Python code is executed line by line by an interpreter. Programs can be run interactively or saved as scripts. Python supports key data types like numbers, strings, lists, and tuples. Strings are sequences of characters that can be accessed using indexing and slicing.

Uploaded by

DamnBJ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

INTRODUCTION TO PYTHON

• Python is a general-purpose language it is


Interpreted, Interactive, Object-oriented,
and High- Level Programming Language.

• Guido van Rossum – 1989 2.0 - 2000,3.0 -


2008
• Monty Python’s flying circus
• Python is interpreted: Python is processed at
runtime by the interpreter. You do not need to
compile your program before executing it.
• Python is Interactive: You can actually sit at a
Python prompt and interact with the interpreter
directly to write your programs.
• Python is Object-Oriented: Python supports Object-
Oriented style or technique of programming that
encapsulates code within objects.
• Python is a Beginner's Language: Python is a great
language for the beginner- level programmers and
supports the development of a wide range of
applications.
• High Level Language: When writing programs,
programmers concentrate on solutions of the current
problem, no need to worry about the low level details.
• Easy-to-learn: Python is clearly defined and
easily readable. The structure of the program is
very simple. It uses few keywords.
• Easy-to-maintain: Python's source code is fairly
easy-to-maintain.
• Portable: Python can run on a wide variety of
hardware platforms and has the same interface on
all platforms.
• Scalable: Python provides a better structure and
support for large programs than shell scripting.
• Free and Open Source: Anyone can freely
distribute it, read the source code, and edit it.
Commonly Used
– Bit Torrent file sharing
– Google search engine, Youtube
– Intel, Cisco, HP, IBM
– i–Robot
– NASA
PYTHON INTERPRETER

• Interpreter: To execute a program in a high-


level language by translating it one line at a
time.
• Compiler: To translate a program written in a
high-level language into a low-level language
all at once, in preparation for later execution.
• MODES OF PYTHON INTERPRETER:

• Python Interpreter is a program that reads and executes


Python code.
– It uses 2 modes of Execution.
• Interactive Mode
• Script Mode

• Interactive mode:
– Interactive Mode, When we type Python statement, interpreter
displays the result(s) immediately.
• Advantages:
– Working in interactive mode is convenient for beginners
and for testing small pieces of code.
• Drawback:
– We cannot save the statements and have to retype all the
statements once again to re-run them.
• In interactive mode, you type Python programs
and the interpreter displays the result:
• >>> 1 + 1
• 2
• >>>, is the prompt the interpreter uses to
indicate that it is ready for you to enter code.
• If you type 1 + 1, the interpreter replies 2.
• >>> print ('Hello, World!') Hello, World!
• Script mode:
– In script mode, we type python program in a file
and then use interpreter to execute the content of
the file.
– Scripts can be saved to disk for future use.
– Python scripts have the extension.py, meaning
that the filename ends with .py
– Save the code with filename.py and run the
interpreter in script mode to execute the script.
• Integrated Development Learning
Environment (IDLE):
– Is a graphical user interface which is completely
written in Python.
– It is bundled with the default implementation of
the python language and also comes with optional
part of the Python packaging.
• Features of IDLE:
– Multi-window text editor with syntax highlighting.
– Auto completion with smart indentation.
– Python shell to display output with syntax
highlighting
VALUES and DATA TYPES
• Value:
– Value can be any letter ,number or string.
– Eg, Values are 2, 42.0, and 'Hello, World!'. (These
values belong to different datat ypes.)
• Data type:
– Every value in Python has a data type.
– It is a set of values, and the allowable operations
on those values.
Numbers:
▪ Number data type stores Numerical Values.
▪ This data type is immutable [i.e. values/items
cannot be changed].
▪ Python supports integers, floating point
numbers and complex numbers. They are
defined as.
• 2. Sequence:
• A sequence is an ordered collection of items, indexed by positive
integers.
• It is a combination of mutable (value can be changed) and immutable
(values cannot be changed) data types.

There are three types of sequence data type available in Python, they are
– Strings
– Lists
– Tuples
• A String in Python consists of a series or sequence of characters - letters,
numbers, and special characters.
– Strings are marked by quotes:
• single quotes (' ') Eg, 'This a string in single quotes'
• double quotes (" ") Eg, "'This a string in double quotes'"
• triple quotes(""" """) Eg, This is a paragraph. It is made up of multiple lines
and sentences."""
– Individual character in a string is accessed using a subscript
(index).
– Characters can be accessed using indexing and slicing operations
• Indexing:

• Positive indexing helps in accessing the string from the


beginning
• Negative subscript helps in accessing the string from the end.
• Subscript 0 or –ve n(where n is length of the string) displays
the first element.
• Example: A[0] or A[-5] will display “H”
• Subscript 1 or –ve (n-1) displays the second element.
• Indexing
• Slicing
• Concatenation
• Repetitions
• Member ship

You might also like