Data Types in Python
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answer ( 1 )
Python provides us with five kinds of data types:
Numbers – Numbers use to hold numerical values.
1. >>> a=7.0
2. >>>
Strings – A string is a sequence of characters. We declare it using single or double quotes.
1. >>> title=”Ayushi’s Book”
Lists – A list is an ordered collection of values, and we declare it using square brackets.
1. >>> colors=[‘red’,’green’,’blue’]
2. >>> type(colors)
Tuples – A tuple, like a list, is an ordered collection of values. The difference.
However, is that a tuple is immutable. This means that we cannot change a value in it.
1. >>> name=(‘Ayushi’,’Sharma’)
2. >>> name[0]=’Avery’
3.
Traceback (most recent call last):
File “”, line 1, in
name[0]=’Avery’
TypeError: ‘tuple’ object does not support item assignment
Dictionary – A dictionary is a data structure that holds key-value pairs. We declare it using curly braces.
1. >>> squares={1:1,2:4,3:9,4:16,5:25}
2. >>> type(squares)