2. INTRODUCTION
• Python is a widely used high-level programming language.
• general-purpose for programming.
• created by “Guido van Rossum” and first released in 1991.
• It is an interpreted language.
• It is easy to read more closer to user
• Read like English language.
Useful areas:
*Scripts *Web-site development
*Text processing *Scientific computing
*Education
3. FEATURES OF PYTHON:
• It is a dynamic type system
• Automatic memory management
• Support multiple programming including object-oriented, imperative,
functional programming and procedure styles.
• It has large and comprehensive standard library
Simple;
• it is simple language
• Reading good Python program feels almost like English (but very strict
English)
East to Learn;
• Python has an extraordinally simple syntax
4. Free and open source;
• Python is an example of a FLOSS(Free / Libra and Open Source Software)
• We can freely distribute the copies of the software.
High-level language;
• When you write programs in Python you never need to bother about low-
level details.
Portable;
• Python has been ported to many platforms,
• Python programs will work any platform without any changes,
ex; Linux, windows ect
Object Oriented;
• Python has very powerful but simple way of doing object oriented
programming
• Especially compared languages like C++ or Java
6. Python NUMBERS
• Numbers are created by numeric literals.
• Numeric objects are immutable,
• When an object is created its value cannot be changed.
• Python has three distinct numeric types:
INTEGERS-
i. Integers represent negative and positive integers without fractional parts,
ii. Integers can be of any length, it is only limited by the memory available
Character P Y T H O N
Index(from left) 0 1 2 3 4 5
Index(from right) -6 -5 -4 -3 -2 -1
7. FLOATING POINT -
i. floating point numbers represents negative and positive numbers with
fractional parts.
ii. It is accurate up to 15 decimal places.
iii. Integer and floating points are separated by decimal points.
ex: 1 is integer, 1.3 is floating point
8. COMPLEX NUMBERS:
i. Complex numbers have a real and imaginary part
ii. The form A+Bi where i is the imaginary number.
iii. Python supports complex numbers either by specifying the number in
(real + imagJ) or (real + imagj) form.
9. PYTHON LIST
• List is an ordered sequence of items,
• It is one of the most used data type in Python & is very flexible.
• All the item of the list do not need to be of the same type,
• Items are separated by ‘comma’ and enclosed with ‘brackets’
• List are Mutable.
• A list without any element is called an empty list.
• list indices start at 0.
• As positive integers are used to index from the left end and negative
integers are used to index from the right end, so every item of a list gives
two alternatives indices.
• Let create a color list with four items.
Item RED Blue Green Black
Index (from left) 0 1 2 3
Index (from right) -4 -3 -2 -1
>>> a= [1, 2.2, ‘PYTHON’]
10. • We can use slicing operators [ ] to extract an item or range of
item from a list
Ex;
• List are mutable, that mean value of the elements list can be
altered
Ex
>>> a = [ 5,10,15,20,25,30,35,40,45 ]
>>> a = [ 2 ]
15
>>> a [ 0 : 3 ]
5,10,15
>>> a [5 : ]
30,35,40,45
>>> a = [ 1, 2, 3 ]
>>> a [ 2 ] = 4
>>> a
[ 1, 2, 4 ]
11. PYTHON TUPLE
• Tuple is an ordered sequence of items same as list.
• A tuple is a series of comma-separated values (items or elements) between
parentheses.
• Tuples are immutable (i.e. you cannot change its content once created)
• The tuple indices start at 0.
• We can use the slicing operators [ ] to extract items but cannot change the
value.
Join tuple:
• We can join the two tuples
Ex
>>> a = ( 5, ‘Program’ , 1+3j )
>>> tup1 = ( 1, 2, 3 )
>>> tup2 = ( 4, 5, 6 )
>>> tup1 + tup2
1, 2, 3, 4, 5, 6
>>> tup1 * 2
1, 2, 3, 1, 2, 3
12. Count; number of times appearance (tup.count (x)
Index; position of the item or element (tup.index(x)
ex; Tup.count
>>> Animals.( ‘cow’, ‘dog’, ‘cat’, ‘monkey’, ‘tiger’, ‘cat ‘)
>>> Animals.count ( ‘cat ‘)
2
>>> Animals.count ( ‘donkey’ )
0
Tup.index
>>> Animals.index ( ‘cat’ )
2
>>> Animals.index ( ‘donkey’ )
error
13. PYTHON STRING
• String is sequence of Unicode characters.
• a string type object is a sequence (left-to- right order) of characters.
• Strings start and end with single or double quotes.
• Multi line string can be denoted using triple quotes,
• Python strings are Immutable.
• Single and double quoted strings are same and you can use a single quote
within a string when it is surrounded by double quote and vice versa.
• Like list ,tuple and slicing operator can be used with string.
Ex;
>>> a = “Hello Friends”
>>> a [ 4 ]
‘o’
>>> a [ 6 : 12 ]
‘Friends’
14. PYTHON SET;
• Set is an unordered collection of unique item.
• Set is defined by value and value separated by comma inside the braces { }
• Basic uses include dealing with set theory
• eliminating duplicate entries.
Ex;
>>> a = { 1, 2, 2, 3, 3, 3, 4 }
>>> a
{ 1, 2, 3 }
15. PYTHON DICTIONARY;
• Dictionary is an unordered collection of key and value pairs.
• It generally used when we have a huge amount of data,
• Dictionary are optimized for retrieving data
• We must know the key to retrieve the value
• In Python Dictionary are defined within curly braces{ }
• Each item being a pair in the form key : value
• The items in a dictionary are a comma-separated list of key:value pairs
where keys and values are Python data type.
>>> a = { 1 : ‘value’ , ‘key’ : 2 }
16. • Dictionary mutable type but we can change only value
• Key cannot repeated more then one value
• You can create an empty dictionary using empty curly braces
Ex;
>>> Fruits = { ‘orange’ : 2, ‘apple’ : 4, ‘banana’ : 5
>>> Fruits [ ‘ apple ‘ ] = 6
fruits = { ‘apple’ : 6 }
17. Conversion between data type
• We can convert between different data types by using different type
conversion functions like int( ), float( ), str( ) etc.
• Conversion from float to int
• Conversion to and from string must contain compatible values.
>>> float ( 5 )
5.0
>>> int ( 10. 6 )
10
>>> int (-10.6 )
-10
>>> float ( ‘ 2.5 ‘)
2.5
>>> str ( 25 )
‘ 25 ‘
18. • We can even convert one sequence into another
• To convert each dictionary, each element must be a pair.
>>> set ( [ 1, 2, 3 ] )
{ 1, 2, 3 }
>>> tuple ( { 5, 6, 7 } )
( 5, 6, 7 )
>>> list ( ‘hello’ )
[ ‘h’, ‘e’, ‘l’, ‘l’, ‘o’ ]
>>> dict ( [ [ 1, 2], [3, 4] ] )
{ 1 : 2, 3 : 4 }