diff options
Diffstat (limited to 'python.html.markdown')
-rw-r--r-- | python.html.markdown | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/python.html.markdown b/python.html.markdown index f8f712d3..28b0a7ae 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -8,20 +8,22 @@ contributors: filename: learnpython.py --- -Python was created by Guido Van Rossum in the early 90s. It is now one of the most popular -languages in existence. I fell in love with Python for its syntactic clarity. It's basically -executable pseudocode. +Python was created by Guido Van Rossum in the early 90s. It is now one of the +most popular languages in existence. I fell in love with Python for its +syntactic clarity. It's basically executable pseudocode. -Feedback would be highly appreciated! You can reach me at [@louiedinh](http://twitter.com/louiedinh) or louiedinh [at] [google's email service] +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. Python 2.7 is reaching end of life and will stop being maintained in 2020, -it is though recommended to start learning Python with Python 3. -For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/). +Note: This article applies to Python 2.7 specifically, but should be applicable +to Python 2.x. Python 2.7 is reaching end of life and will stop being +maintained in 2020, it is though recommended to start learning 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. +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 @@ -32,6 +34,7 @@ allow you to write Python 3 code that will run on Python 2, so check out the Pyt as comments """ + #################################################### ## 1. Primitive Datatypes and Operators #################################################### @@ -124,7 +127,7 @@ not False # => True "This is a string"[0] # => 'T' #String formatting with % -#Even though the % string operator will be deprecated on Python 3.1 and removed +#Even though the % string operator will be deprecated on Python 3.1 and removed #later at some time, it may still be good to know how it works. x = 'apple' y = 'lemon' @@ -188,6 +191,7 @@ some_other_var # Raises a name error # Equivalent of C's '?:' ternary operator "yahoo!" if 3 > 2 else 2 # => "yahoo!" + # Lists store sequences li = [] # You can start with a prefilled list @@ -441,6 +445,7 @@ with open("myfile.txt") as f: for line in f: print line + #################################################### ## 4. Functions #################################################### @@ -464,7 +469,6 @@ def varargs(*args): varargs(1, 2, 3) # => (1, 2, 3) - # You can define functions that take a variable number of # keyword args, as well, which will be interpreted as a dict by using ** def keyword_args(**kwargs): @@ -657,6 +661,12 @@ math.sqrt == m.sqrt == sqrt # => True import math dir(math) +# If you have a Python script named math.py in the same +# folder as your current script, the file math.py will +# be loaded instead of the built-in Python module. +# This happens because the local folder has priority +# over Python's built-in libraries. + #################################################### ## 7. Advanced @@ -692,7 +702,6 @@ for i in double_numbers(xrange_): # message from functools import wraps - def beg(target_function): @wraps(target_function) def wrapper(*args, **kwargs): @@ -703,13 +712,11 @@ def beg(target_function): return wrapper - @beg def say(say_please=False): msg = "Can you buy me a beer?" return msg, say_please - print say() # Can you buy me a beer? print say(say_please=True) # Can you buy me a beer? Please! I am poor :( ``` @@ -726,6 +733,8 @@ print say(say_please=True) # Can you buy me a beer? Please! I am poor :( * [Python Module of the Week](http://pymotw.com/2/) * [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182) * [First Steps With Python](https://realpython.com/learn/python-first-steps/) +* [LearnPython](http://www.learnpython.org/) +* [Fullstack Python](https://www.fullstackpython.com/) ### Dead Tree |