Data Types in Python

Question

What are the common built-in data types in Python?

in progress 0
Pragya Rani 55 years 1 Answer 783 views Contributor 0

Answer ( 1 )

  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)

Leave an answer

Browse
Browse