Python

Concatenation >>>’Zend’ + ‘Anwar’ Zendanwar >>>’Zend’ *3 ZendZendZend Iterating Through String >> count = 0 >>> for str in ‘Zend Anwar’: if(str == ‘n’): count += 1 >>> print(count, “String Found”) 2 String Found  

def functionname(parameters): “””docstring””” statement(s) return [expression] Example: #!/usr/bin/python # Function definition is here def ima( lovestr ): “This prints a passed string into this function” print lovestr return; # Now you can call ima function ima(“I’m fall in love!”)

>>> star =  input(“Enter the star to draw: “) Enter the star to draw: * >>> limit = int(input(“Enter the limit: “)) Enter the limit: 10 >>> for i in range(1, limit+1): print (star*i) Output–    * ** *** **** ***** ****** ******* ******** ********* **********

>>> for var in “zend-anwar”: if var == “-“: continue print (var) output– z e n d a n w a r

>>> for var in “zend-anwar”: if var == “-“: break print (var) output—    z e n d

The Internet Protocol assigns a 4-byte address to every computer connected to the network. Such addresses are usually written as four decimal numbers, separated by periods, which each represent a single byte of the address. Each number can therefore range from 0 to 255. So an IP address looks like this: 202.168.3.180 Because purely numeric
Read More

def can contain multiple expressions whereas lamda is a single expression function def creates a function and assigns a name so as to call it later. lambda creates a function and returns the function itself def can have return statement. lambda cannot have return statements lambda can be used inside list, dictionary.

>>> sqr = [] >>> for i in range(10): sqr.append(i**2) >>> sqr [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Combination  comb = [] >>> for i in [1, 5, 3]: for j in [2,1,5]: if i!=j: comb.append((i,j)) >>> comb [(1, 2), (1, 5), (5, 2), (5, 1), (3, 2), (3, 1), (3,
Read More

>>> stack = [11,22,33,44,55,66,77] >>> stack.append(88) >>> stack [11, 22, 33, 44, 55, 66, 77, 88] >>> stack.append(99) >>> stack [11, 22, 33, 44, 55, 66, 77, 88, 99] >>> stack.pop() 99 >>> stack.pop() 88 >>> stack.pop() 77 >>> stack.pop() 66 >>> stack [11, 22, 33, 44, 55]

Python list >>> arr = [22, 33, 44, 55, 66, 77, 1, 2, 3, 4, 5, 6] >>> arr [22, 33, 44, 55, 66, 77, 1, 2, 3, 4, 5, 6] >>> arr.index(2) 7 >>> arr.remove(77) >>> arr [22, 33, 44, 55, 66, 1, 2, 3, 4, 5, 6] >>> arr.reverse() >>> arr [6, 5,
Read More