3. Python is a general purpose programming language that is often applied in
scripting roles.
Python is also called as Interpreted language
Python supports multiple programming paradigms including imperative, procedural
, functional and object oriented programming style.
Python can be used for • System programming • Graphical User Interface
Programming • Internet Scripting • Component Integration • Database
Programming • Gaming, Images, XML , Robot and more .
Python interpreters are available for installation on many operating systems,
allowing Python code execution on a wide variety of systems. Eg- IDLE
INTRODUCTION
4. KEYWORDS IN PYTHON
KEYWORDS
CLASS
PRIVATE VARIABLE
STRONGLY PRIVATE VARIABLE
SPECIAL PURPOSE
if, while
Complex, Exception
_aadharnum, _accountnum
__mobilenum, __loginid
__add__, __init__
Higher level programming languages like python provides a predefined
set of keywords using which a program is coded.
5.
6. • Numeric Any representation of data which has numeric value.
Python identifies three types:-
1. INTEGER Positive and negative whole numbers. Examples: 1234, -2 etc.
2. FLOAT Real numbers with a floating point representation Examples: -
55.550
3.COMPLEX NUMBERS A number with a real and imaginary component is
represented as a + bj in Python where a and b are floats and
j = √-1. Examples: 4+6j.
DATATYPES IN PYTHON
7. • BOOLEAN: Any representation of data which has two values
denoted by True and False.
• SEQUENCE: An ordered collection of similar or different data
types. The built-in Sequence data types in python are:
1. STRING: A collection of one or more characters put in single,
double or triple quotes. Examples: ‘Hello’, "Hello",
"'Hello'", """Hello""“.
2. LIST: An ordered collection of one or more data items, not
necessarily of same type, put in square brackets. Examples:
[1,"Ravi",75.50, True].
3. TUPLE: Similar to list but he contents of a tuple cannot be modified – it is
immutable - after the tuple is created. Examples: (1,"Ravi", 75.50, True).
8. • DICTIONARY An unordered collection of data in key:value pair
form. Collection of such pairs is enclosed in curly brackets.
Example:
{1:"Superman", 2:"Wonder Woman", 3:"Thor", 4: "Hulk", 5:"Black
Widow“}
9.
10. PROGRAMMING IN PYTHON
INTERACTIVE MODE:-Invoking the interpreter without passing a
script file as a parameter brings up the following prompt −
type the following text at the Python prompt and press the Enter −
this produces the following result −
Interactive mode is not suitable for automated processes. So we use scripting mode.
11. SCRIPTING MODE: Instead of executing one statement at a time we write all the
statement in a text file with .py extension. This script is commonly known as a python
program which can be executed through command line or from run menu of IDLE.
Advantages:
• Easily insert update and delete statements.
• Code or functions from a script can be inserted.
• Automate and schedule.
12. MATH OPERATOR IN PYTHON
>>> print 3 + 12
15
>>> print 12 – 3
9
>>> print 9 + 5 – 15 + 12
11
Operators: add: +
subtract: -
Math Rule: If you want Python to answer in floats, you have to talk to it in floats.
More operators: divide: /
multiply: *
>>> print 3 * 12
36
>>> print 12.0 / 3.0
4.0
13. STRINGS IN PYTHON
Strings operators:
Concatenation: + Adds values on either side of the operator
Try concatenating:
: >>> print “Hello” + “ “ + “world!”
Hello world
Multiplying: * Creates new strings, concatenating multiple copies of the
same string
Try multiplying
>>> print “HAHA” * 250
14. MODULE IN PYTHON:
A module allows you to logically organize your Python code. Grouping related code
into a module makes the code easier to understand and use. A module is a Python
object with arbitrarily named attributes that you can bind and reference.
Simply, a module is a file consisting of Python code. A module can define
functions, classes and variables. A module can also include runnable code.
The Import Statement:
When the interpreter encounters an import statement, it imports the module if the
module is present in the search path.
When the above code is executed, it produces the following result −
15. OBJECT ORIENTED PROGRAMMING:
Python is a multi-paradigm programming language. It supports different
programming approaches.
One of the popular approaches to solve a programming problem is by
creating objects. This is known as Object-Oriented Programming
(OOP).
An object has two characteristics:
• attributes
• Behavior
Let's take an example:A parrot is can be an object,as it has the
following properties:
• name, age, color as attributes
• singing, dancing as behavior
The concept of OOP in Python focuses on creating reusable code.
16. CONNECTING TO SQLITE DATABASE
MySQLdb is an interface for connecting to a MySQL database server from Python
After creating a database in mysql, we need to connect it to the python code.we
follow the following steps for connectivity to the database: