mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
fixed whitespaces & content extending beyond 80 chars
This commit is contained in:
parent
2f3597efc4
commit
5f89f277b9
@ -8,20 +8,22 @@ contributors:
|
|||||||
filename: learnpython.py
|
filename: learnpython.py
|
||||||
---
|
---
|
||||||
|
|
||||||
Python was created by Guido Van Rossum in the early 90s. It is now one of the most popular
|
Python was created by Guido Van Rossum in the early 90s. It is now one of the
|
||||||
languages in existence. I fell in love with Python for its syntactic clarity. It's basically
|
most popular languages in existence. I fell in love with Python for its
|
||||||
executable pseudocode.
|
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
|
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,
|
to Python 2.x. Python 2.7 is reaching end of life and will stop being
|
||||||
it is though recommended to start learning Python with Python 3.
|
maintained in 2020, it is though recommended to start learning Python with
|
||||||
For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/).
|
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,
|
It is also possible to write Python code which is compatible with Python 2.7
|
||||||
using Python [`__future__` imports](https://docs.python.org/2/library/__future__.html). `__future__` imports
|
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.
|
allow you to write Python 3 code that will run on Python 2, so check out the
|
||||||
|
Python 3 tutorial.
|
||||||
|
|
||||||
```python
|
```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
|
as comments
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
## 1. Primitive Datatypes and Operators
|
## 1. Primitive Datatypes and Operators
|
||||||
####################################################
|
####################################################
|
||||||
@ -188,6 +191,7 @@ some_other_var # Raises a name error
|
|||||||
# Equivalent of C's '?:' ternary operator
|
# Equivalent of C's '?:' ternary operator
|
||||||
"yahoo!" if 3 > 2 else 2 # => "yahoo!"
|
"yahoo!" if 3 > 2 else 2 # => "yahoo!"
|
||||||
|
|
||||||
|
|
||||||
# Lists store sequences
|
# Lists store sequences
|
||||||
li = []
|
li = []
|
||||||
# You can start with a prefilled list
|
# You can start with a prefilled list
|
||||||
@ -441,6 +445,7 @@ with open("myfile.txt") as f:
|
|||||||
for line in f:
|
for line in f:
|
||||||
print line
|
print line
|
||||||
|
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
## 4. Functions
|
## 4. Functions
|
||||||
####################################################
|
####################################################
|
||||||
@ -464,7 +469,6 @@ def varargs(*args):
|
|||||||
|
|
||||||
varargs(1, 2, 3) # => (1, 2, 3)
|
varargs(1, 2, 3) # => (1, 2, 3)
|
||||||
|
|
||||||
|
|
||||||
# You can define functions that take a variable number of
|
# You can define functions that take a variable number of
|
||||||
# keyword args, as well, which will be interpreted as a dict by using **
|
# keyword args, as well, which will be interpreted as a dict by using **
|
||||||
def keyword_args(**kwargs):
|
def keyword_args(**kwargs):
|
||||||
@ -698,7 +702,6 @@ for i in double_numbers(xrange_):
|
|||||||
# message
|
# message
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
def beg(target_function):
|
def beg(target_function):
|
||||||
@wraps(target_function)
|
@wraps(target_function)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
@ -709,13 +712,11 @@ def beg(target_function):
|
|||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@beg
|
@beg
|
||||||
def say(say_please=False):
|
def say(say_please=False):
|
||||||
msg = "Can you buy me a beer?"
|
msg = "Can you buy me a beer?"
|
||||||
return msg, say_please
|
return msg, say_please
|
||||||
|
|
||||||
|
|
||||||
print say() # Can you buy me a beer?
|
print say() # Can you buy me a beer?
|
||||||
print say(say_please=True) # Can you buy me a beer? Please! I am poor :(
|
print say(say_please=True) # Can you buy me a beer? Please! I am poor :(
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user