Data Types

1. Number

Note

Types of Number

  • int (signed integers)

  • float (floating point real values)

  • complex (complex numbers)

Example

int

float

complex

5

5.5

2+4j

-100

8.5555

-i+2j

How to Assign Numbers

a = 10

How to Access Numbers

num1 = 10
num2 = 5.5
num3 = 2+3j
print ("num1 integer: ", num1)
print ("num2 float: ", num2)
print ("num3 complex: ", num3)

Output:

num1 integer:  10
num2 float:  5.5
num3 complex:  (2+3j)

2. Strings

How to Assign Strings

mystr = 'python'

How to Access Strings

mystr = 'python'
print ("mystr[0]: ", mystr[0])
print ("mystr[1:5]: ", mystr[1:5])
print ("mystr[:] ", mystr[:])
print ("mystr[::]: ", mystr[::])

Output:

mystr[0]:  p
mystr[1:5]:  ytho
mystr[:]:  python
mystr[::]:  python

3. Lists

How to Assign List

mylist = ['python',1,5.5,'saurabh','100',True]

How to Access List

mylist = ['python',1,5.5,'saurabh','100',True]
print ("mylist[0]: ", mylist[0])
print ("mylist[1:5]: ", mylist[1:5])
print ("mylist[:]: ", mylist[:])
print ("mylist[::]: ", mylist[::])

Output:

mylist[0]:  python
mylist[1:5]:  [1, 5.5, 'saurabh', '100']
mylist[:]:  ['python', 1, 5.5, 'saurabh', '100', True]
mylist[::]:  ['python', 1, 5.5, 'saurabh', '100', True]

4. Tuple

How to Assign List

mytuple = ('python',1,5.5,'saurabh','100',True)

How to Access List

mytuple = ('python',1,5.5,'saurabh','100',True)
print ("mytuple[0]: ", mytuple[0])
print ("mytuple[1:5]: ", mytuple[1:5])
print ("mytuple[:]: ", mytuple[:])
print ("mytuple[::]: ", mytuple[::])

Output:

mytuple[0]:  python
mytuple[1:5]:  (1, 5.5, 'saurabh', '100')
mytuple[:]:  ('python', 1, 5.5, 'saurabh', '100', True)
mytuple[::]:  ('python', 1, 5.5, 'saurabh', '100', True)

5. Dictionary

How to Assign Dictionary

mydict = {'Name':'Saurabh','Marks': 90,'Subjects':['Maths','Science']}

How to Access Dictionary

mydict = {'Name':'Saurabh','Marks': 90,'Subjects':['Maths','Science']}
print ("mydict['Name']: ", mydict['Name'])
print ("mydict['Marks']: ", mydict['Marks'])
print ("mydict['Subjects']: ", mydict['Subjects'])
print ("mydict: ", mydict)

Output:

mydict['Name']:  Saurabh
mydict['Marks']:  90
mydict['Subjects']:  ['Maths', 'Science']
mydict:  {'Name': 'Saurabh', 'Marks': 90, 'Subjects': ['Maths', 'Science']}