Posted by AnithaKamatchi on Saturday, April 14, 2018 in Python | No comments
Python has 5 standard data types
·
Numbers
Stores numeric values. It is further classified as follows
Ø int
Ø float
Ø double
Ø complex
Syntax:
variable = value
Example: age = 26
·
String
Stores a set of character represented within single/double quotes
Syntax: variable = ‘value’ or variable = “value”
Example: name = ‘Anitha’ or name = “Anitha”
·
List
List are the versatile sequence
type in python. List in python support multiple datatypes separated by comma
and enclosed within square brackets. List are mutable
Syntax: variable = [val1, val2, val3…valn]
Example: empInfo = [‘Anitha’, 26, ’Engineer’]
·
Tuple
Tuple are similar to list but are non-mutable. Unlike list tuple are
enclosed within parenthesis
Syntax: variable = (val1, val2, val3…valn)
Example: studentInfo = (‘Avinash’, 5, ’Grade II’)
·
Dictionary
Dictionaries contains (key, value) pair and are
kind of hash table type. The key can by be any datatype and values can be of
arbitrary python object. Key-value pair are separated by colon : and multiple
key-value pair are separated by comma and enclosed within curly braces {}
Key is unique and value may have duplicates
Syntax: variable = {key1:val1, key2:val2, key3:val3… keyn:valn}
Example: cusInfo = {‘cusID’: 234, ‘name’:’Atul’,’Age’:28,’Gender’:’M’}

0 comments:
Post a Comment