Wednesday, 18 July 2018

11-C Data Types: Numbers, Strings, List and Tuples, Dictionary

Numbers:
a) integers: int
b) booleans  bool(0) - False bool(1) - True
c) floating point numbers: float
d) complex numbers: a= 0+3.1j    b=1.5+2j

Strings:
String is a sequence of characters can be individually accessed using its index

subject="Computers"
subject
'Computers'
subject[-9]
'C'

List 
a=[1,2,3,4,5]
print(a)

Tuples:
p=(1,2,3,4,5)

Value of type list are mutable i.e. changeable- one can change/delete/add a list's elements.  But the values of type tuple are immutable i.e. non-changeable:


Dictionary:
It is an unordered set of comma-separated key:value

example: v= {'a':1,'e':2,'i':3,'o':4,'u':5}

v['a']   ans: 1      v['u'] ans: 5

No comments:

Post a Comment