KEMBAR78
Python programming for Beginners - II | PPTX
Python Programming - II
Data Types, Numbers, Strings, Tuples
Data Types
• Numbers
• String
• List
• Tuple
• Dictionary
Numbers
Type Description
int Signed integer
long Long Integers ( deprecated not available from Python 3.x )
float Floating point real values
complex Contains integer in the range of 0 - 255
Number Samples
>>> a = 382
>>> print (int(a))
382
>>> print (float(a))
382.0
>>> print (complex(a))
(382+0j)
>>> print (complex(a, 10))
(382+10j)
Number Samples …
>>> b = 34
>>> print (int(b))
34
>>> c = 45.5
>>> print (float(c))
45.5
>>> d = int(b) + int(c)
>>> print (d)
79
>>> e = float(b) + float(c)
>>> print (e)
79.5
>>> print (complex(b))
(34+0j)
>>> i = 30
>>> print (complex(b, i))
(34+30j)
>>> h = complex(b,i) + complex(i,b)
>>> print (h)
(64+64j)
>>> k = complex(b,i) * complex(i,b)
>>> print (k)
2056j
>>> k = complex(b,i) + complex(b,i)
>>> print (k)
(68+60j)
>>> k = complex(b,i) * complex(b,i)
>>> print (k)
(256+2040j)
>>> l = float(b) * float(c)
>>> print (l)
1547.0
>>> m = int(b) * int(c)
>>> print (m)
1530
>>>
String
• Character sequence enclosed with in quote
• Denoted by
• single quotes ‘
• double quotes “
• Triple Quotes “””
• Sample
>>> firstName = 'Hariharan'
>>> lastName = "Veerappan“
>>> print (firstName)
Hariharan
>>> print (lastName)
Veerappan
>>> address = """No 16 Ganesh 1st cross street"""
>>> print (address)
List
• Contains a series of values
• Can be declared by using brackets []
• Sample
A = []
B = [1, 4, 56, 78, 45]
C = [“hari”, “haran”, “neevee”]
• Not limited with a single dimension
D = [[], []]
E = [ [1,2,3], [4,5,6]]
• List size determined by “len()”
List Methods
• list.append(elem)
• list.insert(index, elem)
• list.extend(list2)
• list.index(elem)
• list.remove(elem)
• list.sort()
• list.reverse()
• list.pop(index)
Tuples
• Sequence of immutable python objects
• Are sequences, just similar to lists
• Tuples cannot be changed unlike lists
• Uses parathesis, whereas lists uses square brackets
• cmp(tup1,tup2)
• len(tup)
• max(tup)
• min(tup)
• tuple(seq)
Tuple Operations
Python Expression Results Description
len((1,2,3)) 3 Length
(1,2,3) + (4,5,6) (1,2,3,4,5,6) Concatenation
(‘Hi’) * 2 (‘Hi’, ‘Hi’) Repetition
3 in (1,2,3) True Membership
Tuple Sample
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print (tup1[0]: );
print (tup2[1:5]);
tup3 = tup1 + tup2
print(tup3)
Dictionary
• Are lists of key:value
• Powerful datatype holds lot of related information through keys
• Extract the value based on keys
• Created by using braces {} and separated by commas
• Key associated value with :
Dictionary Sample
student = {‘hari’ : 423, ‘haran’:445}
print (student[‘hari’])
print (student[423])
student[‘hari’] = 441
student[‘neevee’] = 233
print(student.keys())
avail = ‘haran’ in student
print (avail)
Arithmetic Operators
Operators Description
+ Adds the two operands
- Subtract the second operand from the first
* Multiplies the operands
/ Divides the first operand by second operand
% Divides first operand by second operand & returns remainder
Relational Operators
Operators Description
== Returns true, if operands are equal. Else returns false
!= Returns true, if both operands are not equal, else false
> Returns true, if first operand is greater, else false
< Returns true, if first operand is lesser, else false
>= Returns true, if first operand is greater or equal, else false
<= Returns true, if first operand is lesser or equal, else false
Bit Wise Operators
Operators Description
& AND both operands bit by bit
| OR both operands bit by bit
~ 1’s complement bit by bit
^ EX-OR both operands bit by bit
>> Rotate right by number of bits
<< Rotate left by number of bits
Assignment Operators
Operators Description
= Assigns left operand with the right operand value
+= Adds the both operand and assign to left operand
-= Subtracts the right from left operand and assign to left
*= Multiplies both operands & assign to left
/= Divides the left operand by right & assign to left
%= Modulus of left operand by right operand & assign to left
>>= Rotate right the left operand & assign to left
<<= Rotate left by right operand & assign to left
Web : www.neeveetech.com
E-Mail : nvhariharan@neeveetech.com
Thank You.

Python programming for Beginners - II

  • 1.
    Python Programming -II Data Types, Numbers, Strings, Tuples
  • 2.
    Data Types • Numbers •String • List • Tuple • Dictionary
  • 3.
    Numbers Type Description int Signedinteger long Long Integers ( deprecated not available from Python 3.x ) float Floating point real values complex Contains integer in the range of 0 - 255
  • 4.
    Number Samples >>> a= 382 >>> print (int(a)) 382 >>> print (float(a)) 382.0 >>> print (complex(a)) (382+0j) >>> print (complex(a, 10)) (382+10j)
  • 5.
    Number Samples … >>>b = 34 >>> print (int(b)) 34 >>> c = 45.5 >>> print (float(c)) 45.5 >>> d = int(b) + int(c) >>> print (d) 79 >>> e = float(b) + float(c) >>> print (e) 79.5 >>> print (complex(b)) (34+0j) >>> i = 30 >>> print (complex(b, i)) (34+30j) >>> h = complex(b,i) + complex(i,b) >>> print (h) (64+64j) >>> k = complex(b,i) * complex(i,b) >>> print (k) 2056j >>> k = complex(b,i) + complex(b,i) >>> print (k) (68+60j) >>> k = complex(b,i) * complex(b,i) >>> print (k) (256+2040j) >>> l = float(b) * float(c) >>> print (l) 1547.0 >>> m = int(b) * int(c) >>> print (m) 1530 >>>
  • 6.
    String • Character sequenceenclosed with in quote • Denoted by • single quotes ‘ • double quotes “ • Triple Quotes “”” • Sample >>> firstName = 'Hariharan' >>> lastName = "Veerappan“ >>> print (firstName) Hariharan >>> print (lastName) Veerappan >>> address = """No 16 Ganesh 1st cross street""" >>> print (address)
  • 7.
    List • Contains aseries of values • Can be declared by using brackets [] • Sample A = [] B = [1, 4, 56, 78, 45] C = [“hari”, “haran”, “neevee”] • Not limited with a single dimension D = [[], []] E = [ [1,2,3], [4,5,6]] • List size determined by “len()”
  • 8.
    List Methods • list.append(elem) •list.insert(index, elem) • list.extend(list2) • list.index(elem) • list.remove(elem) • list.sort() • list.reverse() • list.pop(index)
  • 9.
    Tuples • Sequence ofimmutable python objects • Are sequences, just similar to lists • Tuples cannot be changed unlike lists • Uses parathesis, whereas lists uses square brackets • cmp(tup1,tup2) • len(tup) • max(tup) • min(tup) • tuple(seq)
  • 10.
    Tuple Operations Python ExpressionResults Description len((1,2,3)) 3 Length (1,2,3) + (4,5,6) (1,2,3,4,5,6) Concatenation (‘Hi’) * 2 (‘Hi’, ‘Hi’) Repetition 3 in (1,2,3) True Membership
  • 11.
    Tuple Sample tup1 =('physics', 'chemistry', 1997, 2000); tup2 = (1, 2, 3, 4, 5, 6, 7 ); print (tup1[0]: ); print (tup2[1:5]); tup3 = tup1 + tup2 print(tup3)
  • 12.
    Dictionary • Are listsof key:value • Powerful datatype holds lot of related information through keys • Extract the value based on keys • Created by using braces {} and separated by commas • Key associated value with :
  • 13.
    Dictionary Sample student ={‘hari’ : 423, ‘haran’:445} print (student[‘hari’]) print (student[423]) student[‘hari’] = 441 student[‘neevee’] = 233 print(student.keys()) avail = ‘haran’ in student print (avail)
  • 14.
    Arithmetic Operators Operators Description +Adds the two operands - Subtract the second operand from the first * Multiplies the operands / Divides the first operand by second operand % Divides first operand by second operand & returns remainder
  • 15.
    Relational Operators Operators Description ==Returns true, if operands are equal. Else returns false != Returns true, if both operands are not equal, else false > Returns true, if first operand is greater, else false < Returns true, if first operand is lesser, else false >= Returns true, if first operand is greater or equal, else false <= Returns true, if first operand is lesser or equal, else false
  • 16.
    Bit Wise Operators OperatorsDescription & AND both operands bit by bit | OR both operands bit by bit ~ 1’s complement bit by bit ^ EX-OR both operands bit by bit >> Rotate right by number of bits << Rotate left by number of bits
  • 17.
    Assignment Operators Operators Description =Assigns left operand with the right operand value += Adds the both operand and assign to left operand -= Subtracts the right from left operand and assign to left *= Multiplies both operands & assign to left /= Divides the left operand by right & assign to left %= Modulus of left operand by right operand & assign to left >>= Rotate right the left operand & assign to left <<= Rotate left by right operand & assign to left
  • 18.
    Web : www.neeveetech.com E-Mail: nvhariharan@neeveetech.com Thank You.

Editor's Notes

  • #2 To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.