You are on page 1of 6

9/3/22, 12:21 PM 3_9_22_Python Datatypes Demo.

ipynb - Colaboratory

Python Datatypes
Numbers
Strings
Lists
Tuples
Dictionaries
Boolean
Sets

# Integer

1 + 1

a = 2

b = a + 3

type(b)

int

# Floating Point numbers

9.08 + 0.07

9.15

c = 9.87

d = c + 1.234

type(d)

float

# Strings

https://colab.research.google.com/drive/1vVJeUDprYMS5BI_A5dpOORazQs7P-df-#scrollTo=siEJNMYV3dg-&printMode=true 1/6
9/3/22, 12:21 PM 3_9_22_Python Datatypes Demo.ipynb - Colaboratory

'Hello'

'Hello'

t = 'Hello'

type(t)

str

x = "hello"

type(x)

str

'''jhdjahdsjab

hjjsdh

hsahgd "jhakhksh" jgasjj'''

'jhdjahdsjab\nhjjsdh\nhsahgd "jhakhksh" jgasjj'

# Floor Division

8 / 2

4.0

8 // 2

15 / 4

3.75

15 // 4

# Modulo Division

15 % 4

# TO CHECK THE PRIORITY OF THE OPERATORS 

# PEMDAS

https://colab.research.google.com/drive/1vVJeUDprYMS5BI_A5dpOORazQs7P-df-#scrollTo=siEJNMYV3dg-&printMode=true 2/6
9/3/22, 12:21 PM 3_9_22_Python Datatypes Demo.ipynb - Colaboratory

P ---> PRECEDENCE

E ---> EXPONENTIAL

M ---> MULTIPLICATION

D ---> DIVISION

S ---> SUBTRACTION

# EQUALITY OPERATOR

2 == 2

True

"Hello" == "hello"

False

2.34 == 3.14

False

5 == 5.0

True

# Not equality operator !=

"Hello" != "hello"

True

1 != 1.0

False

# Concatenation of two strings

d = "Hello " + "World"

'Hello World'

# Repeat the strings

d = "Hello " * 5

'Hello Hello Hello Hello Hello '

str = "Python"

https://colab.research.google.com/drive/1vVJeUDprYMS5BI_A5dpOORazQs7P-df-#scrollTo=siEJNMYV3dg-&printMode=true 3/6
9/3/22, 12:21 PM 3_9_22_Python Datatypes Demo.ipynb - Colaboratory

str1 = str + " Programming"

str1

'Python Programming'

# Slicing on the strings Slice operator [] [:]

str1[:]

str[3:5]

str[:-3]

str1[:-3]

str1[-1]

'g'

# Printing with .format() function

num = 12

name = "abc"

print("My num is {} and My name is {}".format(num,name))
print("My num is {one} and my name is {two}".format(one=num,two=name))

My num is 12 and My name is abc

My num is 12 and my name is abc

LISTS

My_list = [1,2,3,"HELLO",9.18]

My_list

[1, 2, 3, 'HELLO', 9.18]

My_list.append(True)

My_list

[1, 2, 3, 'HELLO', 9.18, True, True, True]

My_list = [1,2,3,"HELLO",9.18]

My_list.append('d')

My_list

[1, 2, 3, 'HELLO', 9.18, 'd']

My_list[-1]

'd'

https://colab.research.google.com/drive/1vVJeUDprYMS5BI_A5dpOORazQs7P-df-#scrollTo=siEJNMYV3dg-&printMode=true 4/6
9/3/22, 12:21 PM 3_9_22_Python Datatypes Demo.ipynb - Colaboratory

My_list[0:2]

[1, 2]

My_list[0] = "NEW"

My_list

['NEW', 2, 3, 'HELLO', 9.18, 'd']

nest = [1,2,3,[4,5,["Python"]]]
nest

nest[3]

nest[3][2][0]

d = {'key1':'item1','key2':'item2'}

d['key1']

car_dict = {"brand1":"ford","brand2":"Toyota","brand3":"Volkswagon"}

len(car_dict)

https://colab.research.google.com/drive/1vVJeUDprYMS5BI_A5dpOORazQs7P-df-#scrollTo=siEJNMYV3dg-&printMode=true 5/6
9/3/22, 12:21 PM 3_9_22_Python Datatypes Demo.ipynb - Colaboratory

Colab paid products


-
Cancel contracts here

https://colab.research.google.com/drive/1vVJeUDprYMS5BI_A5dpOORazQs7P-df-#scrollTo=siEJNMYV3dg-&printMode=true 6/6

You might also like