Python Basic

Python Compound Data Types
(List, Tuple, Dictionary and String)

Python Compound data type are most powerful datatypes in compare to other languages. Python having four most important data types (List, Tuple, Dictionary and String). Lets start discussing it in brief.

List

List is the very first compound data type in python that can hold multiple values like array and indexed. Data will be enclose within square braces [] and separated by comma. The difference between normal array and list is- list can hold multiple value of multiple data type where as array can hold only same kind of data. For example –

lst = [4, ,6.7, ‘Hello”, ‘c’]

Here a list is declared with name lst and holding an integer, a float, a string and a single character.

Tuple

Tuple s another compound data type in python that can hold multiple values and indexed. Like array or list but the elements of tuple is immutable (can not changed). Data will be enclose within parenthesis () and separated by comma. For example –

tpl= (4, ,6.7, ‘Hello”, ‘c’)

Here a Tuple is declared with name tpl and holding an integer, a float, a string and a single character.

Dictionary

A dictionary is a collection or compound data type which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.

dict = {'Name' :'Ramesh',
'age': 35,
'gender':'male',
'marks':98.5}

Here a Dictionary is declared with name dict and holding key value pair of name, age, gender and marks.

String

String literal are the datatype which is most common and most useful. You can store a String in double quotes or singe quotes. String is indexed data type and mutable in place.

strdq = "I am String literal" #String with double quotes
strsq = 'I am String literal'  #String with single quotes 
print(strdq)     #print string in python 
print(strsq)

Here a String is declared with strdq and strsq where strdq defined using double quotes and str sq defined using single quotes.

0 thoughts on “Python Basic

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>