From 777423dcc519b2f25bbcf5238c12ee3a0d4c67c9 Mon Sep 17 00:00:00 2001 From: Cadel Watson Date: Wed, 7 Oct 2015 17:01:28 +1100 Subject: Add examples of higher-order functions taking multiple arguments --- python.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 5572e38e..6cfb5dca 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -473,9 +473,12 @@ add_10(3) # => 13 # There are also anonymous functions (lambda x: x > 2)(3) # => True +(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5 # There are built-in higher order functions map(add_10, [1, 2, 3]) # => [11, 12, 13] +map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3] + filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] # We can use list comprehensions for nice maps and filters -- cgit v1.2.3 From 9ee3a687204cbe6caaa11b9fd28470651a70ae2b Mon Sep 17 00:00:00 2001 From: Ankit Aggarwal Date: Sun, 11 Oct 2015 19:51:43 +0530 Subject: Added input operations in learn Python 2.7 doc --- python.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 6cfb5dca..95146ca8 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -4,6 +4,7 @@ contributors: - ["Louie Dinh", "http://ldinh.ca"] - ["Amin Bandali", "http://aminbandali.com"] - ["Andre Polykanine", "https://github.com/Oire"] + - ["Ankit Aggarwal", "http://ankitaggarwal.me"] filename: learnpython.py --- @@ -144,6 +145,10 @@ bool("") # => False # Python has a print statement print "I'm Python. Nice to meet you!" +# Simple way to get input data from console +input_string_var = raw_input("Enter some data: ") # Data is stored as a string +input_number_var = input("Enter a number: ") # Data is stored as a number + # No need to declare variables before assigning to them. some_var = 5 # Convention is to use lower_case_with_underscores some_var # => 5 -- cgit v1.2.3 From ba06e9af37fda3dd363ab5a39bf03cd65bbe2ddd Mon Sep 17 00:00:00 2001 From: Ananya W Cleetus Date: Mon, 12 Oct 2015 11:56:37 -0400 Subject: Update python.html.markdown --- python.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 6cfb5dca..5b36083d 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -142,7 +142,7 @@ bool("") # => False #################################################### # Python has a print statement -print "I'm Python. Nice to meet you!" +print "I'm Python. Nice to meet you!" # => I'm Python. Nice to meet you! # No need to declare variables before assigning to them. some_var = 5 # Convention is to use lower_case_with_underscores -- cgit v1.2.3 From c05400477b05eb2f5f9ef7fb2d168c84e14fc26e Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 13 Oct 2015 17:56:48 -0700 Subject: Update Python 2 vs Python 3 Add fact that Python 2 is reaching end of life. And note that you can use `__future__` to add Python 2 and 3 compatible code. --- python.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 5b36083d..57a4d0d6 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -14,7 +14,13 @@ executable pseudocode. Feedback would be highly appreciated! You can reach me at [@louiedinh](http://twitter.com/louiedinh) or louiedinh [at] [google's email service] Note: This article applies to Python 2.7 specifically, but should be applicable -to Python 2.x. For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/). +to Python 2.x. Python 2.7 is reachong end of life and will stop beeign maintained in 2020, +it is though recommended to start learnign Python with Python 3. +For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/). + +It is also possible to write Python code which is compatible with Python 2.7 and 3.x at the same time, +using Python [`__future__` imports](https://docs.python.org/2/library/__future__.html). `__future__` imports +allow you to write Python 3 code that will run on Python 2, so check out the Python 3 tutorial. ```python -- cgit v1.2.3 From e1d2f8c718858323e1716cc0bde4c652e9b87ce6 Mon Sep 17 00:00:00 2001 From: Ankit Aggarwal Date: Wed, 14 Oct 2015 10:27:25 +0530 Subject: Updated the input() method usage and description --- python.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 95146ca8..11642ff8 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -4,7 +4,6 @@ contributors: - ["Louie Dinh", "http://ldinh.ca"] - ["Amin Bandali", "http://aminbandali.com"] - ["Andre Polykanine", "https://github.com/Oire"] - - ["Ankit Aggarwal", "http://ankitaggarwal.me"] filename: learnpython.py --- @@ -146,8 +145,10 @@ bool("") # => False print "I'm Python. Nice to meet you!" # Simple way to get input data from console -input_string_var = raw_input("Enter some data: ") # Data is stored as a string -input_number_var = input("Enter a number: ") # Data is stored as a number +input_string_var = raw_input("Enter some data: ") # Returns the data as a string +input_var = input("Enter some data: ") # Evaluates the data as python code +# Warning: Caution is recommended for input() method usage +# Note: In python 3, input() is deprecated and raw_input() is renamed to input() # No need to declare variables before assigning to them. some_var = 5 # Convention is to use lower_case_with_underscores -- cgit v1.2.3