Difference between lamda and def in Python
-
zendnwar
-
March 18, 2016
-
Python
-
0 Comments
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.
Continue Reading
Python List Comprehensions
-
zendnwar
-
March 17, 2016
-
Python
-
0 Comments
>>> 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, 5)
Continue Reading
Python Lists as Stacks
-
zendnwar
-
March 17, 2016
-
Python
-
0 Comments
>>> 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
Continue Reading
Data structure in python
-
zendnwar
-
March 17, 2016
-
Python
-
0 Comments
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, 4, 3, 2, 1, 66, …
Continue Reading
Python Keywords and Identifier
-
zendnwar
-
March 10, 2016
-
Python
-
0 Comments
Keywords Keywords are the reserved words in Python. We cannot use a keyword as variable name, function name or any other identifier. They are used to define the syntax and structure of the Python language. In Python, keywords are case sensitive. Python is a dynamic language. It changes during time. The list of keywords may change in the future. There …
Continue Reading
Write a Hello World Python Program in linux
-
zendnwar
-
March 8, 2016
-
Python
-
0 Comments
$ vim zendanwar.py #!/usr/bin/python # Hello world python program print “Hello python World!” save the the file Make the permission with following comman $ chmod +x zendanwar.py lastly run your file $ zendanwar.py output : Hello python World!
Continue Reading
how to check python version in linux?
-
zendnwar
-
March 8, 2016
-
Python, Uncategorized
-
5 Comments
It’s very simple: python –version or python -V
Continue Reading
‘pip’ is not recognized as an internal or external command in Python
-
zendnwar
-
March 1, 2016
-
Python
-
1 Comment
pip now comes bundled with new versions of python: Need to add the path for pip installation to system variable. By default, pip is installed to C:\Python34\Scripts\pip so the path “C:\Python34\Scripts” needs to be added the “path” variable.
Continue Reading
Database connection between python & mysql
-
zendnwar
-
November 29, 2015
-
Python
-
0 Comments
#!/usr/bin/python import MySQLdb db = MySQLdb.connect(“localhost”,”user”,”password”,”dbname” ) cursor = db.cursor()
Continue Reading
Some sorting example in paython.
-
zendnwar
-
March 6, 2014
-
Python
-
0 Comments
>>> sorted(5, 2, 3, 1, 4,8,9,7) output : 1, 2, 3, 4, 5, 7, 8, 9 list.sort() method : >>> a= 5, 2, 3, 1, 4,8,9,7 >>> a.sort() >>> a output : 1, 2, 3, 4, 5, 7, 8, 9 Key Functions : >>> sorted(“a key parameter to specify a function to be called on each list element prior to …
Continue Reading