Posts

Tuple, List, Dictionary, String Slice

 String Slice: str='I love python.' >>> print(str) I love python. >>> print(str[0]) I >>> print(str[-1]) . >>> print(str[7:12]) pytho >>> print(str[7:13]) python >>> print(str[7:13]*5) pythonpythonpythonpythonpython >>> print('hello '*5) hello hello hello hello hello >>> print(str[5:]) e python. >>> print(str[:5]) I lov   Tuple: A tuple is similar to the list as it also consists of a number of values separated by commas and enclosed within parentheses. Value within tuple can not be changed.   >>> t=(10,'ten',11,'eleven') >>> t (10, 'ten', 11, 'eleven') >>> print(t) (10, 'ten', 11, 'eleven') >>> print(t[0]) 10 >>> print(t*2) (10, 'ten', 11, 'eleven', 10, 'ten', 11, 'eleven') >>> print(t+t) (10, 'ten', 11, 'eleven', 10, 'ten', 11, 'e