Tutorial by Examples

Numbers have four types in Python. Int, float, complex, and long. int_num = 10 #int value float_num = 10.2 #float value complex_num = 3.14j #complex value long_num = 1234567L #long value
String are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Strings are immutable sequence data type, i.e each time one makes any changes to a string, completely new string object is created. a_str = 'Hello ...
A list contains items separated by commas and enclosed within square brackets [].lists are almost similar to arrays in C. One difference is that all the items belonging to a list can be of different data type. list = [123,'abcd',10.2,'d'] #can be a array of any data type or single data type. li...
Lists are enclosed in brackets [ ] and their elements and size can be changed, while tuples are enclosed in parentheses ( ) and cannot be updated. Tuples are immutable. tuple = (123,'hello') tuple1 = ('world') print(tuple) #will output whole tuple. (123,'hello') print(tuple[0]) #will outp...
Dictionary consists of key-value pairs.It is enclosed by curly braces {} and values can be assigned and accessed using square brackets[]. dic={'name':'red','age':10} print(dic) #will output all the key-value pairs. {'name':'red','age':10} print(dic['name']) #will output only value with 'nam...
Sets are unordered collections of unique objects, there are two types of set : Sets - They are mutable and new elements can be added once sets are defined basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) # duplicates will be removed > {'orange', ...

Page 1 of 1