mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 23:33:00 +03:00
Merge
This commit is contained in:
commit
9d8d871005
@ -14,12 +14,12 @@ properly!
|
||||
|
||||
## Contributing
|
||||
|
||||
All contributions welcome, from the tiniest typo to a brand new article. Translations
|
||||
All contributions are welcome, from the tiniest typo to a brand new article. Translations
|
||||
in all languages are welcome (or, for that matter, original articles in any language).
|
||||
Send a pull request or open an issue any time of day or night.
|
||||
|
||||
**Please tag your issues pull requests with [language/lang-code] at the beginning**
|
||||
**(e.g. [python/en] for english python).** This will help everyone pick out things they
|
||||
**(e.g. [python/en] for English Python).** This will help everyone pick out things they
|
||||
care about.
|
||||
|
||||
### Style Guidelines
|
||||
@ -27,7 +27,7 @@ care about.
|
||||
* **Keep lines under 80 chars**
|
||||
* **Prefer example to exposition**
|
||||
* **Eschew surplusage**
|
||||
* **Use utf-8**
|
||||
* **Use UTF-8**
|
||||
|
||||
Long version:
|
||||
|
||||
@ -38,28 +38,28 @@ Long version:
|
||||
|
||||
* We welcome newcomers, but the target audience for this site is programmers with some experience.
|
||||
So, try to avoid explaining basic concepts except for those specific to the language in question,
|
||||
to keep articles succinct and scannable. We all know how to use google here.
|
||||
to keep articles succinct and scannable. We all know how to use Google here.
|
||||
|
||||
* For translations (or english articles with non-ASCII characters), please make sure your file is
|
||||
utf-8 encoded, and try to leave out the byte-order-mark at the start of the file. (`:set nobomb` in vim)
|
||||
* For translations (or English articles with non-ASCII characters), please make sure your file is
|
||||
UTF-8 encoded, and try to leave out the byte-order-mark at the start of the file. (`:set nobomb` in Vim)
|
||||
|
||||
### Header configuration
|
||||
|
||||
The actual site uses Middleman to generate HTML files from these markdown ones. Middleman, or at least
|
||||
The actual site uses Middleman to generate HTML files from these Markdown ones. Middleman, or at least
|
||||
the custom scripts underpinning the site, required that some key information be defined in the header.
|
||||
|
||||
The following fields are necessary for english articles about programming languages:
|
||||
The following fields are necessary for English articles about programming languages:
|
||||
|
||||
* **language** The *programming language* in question
|
||||
* **contributors** A list of [author, url] lists to credit
|
||||
* **contributors** A list of [author, URL] lists to credit
|
||||
|
||||
Other fields:
|
||||
|
||||
* **filename**: The filename for this article's code. It will be fetched, mashed together, and made downloadable.
|
||||
For non-english articles, *filename* should have a language-specific suffix.
|
||||
For non-English articles, *filename* should have a language-specific suffix.
|
||||
* **lang**: For translations, the human language this article is in. For categorization, mostly.
|
||||
|
||||
Here's an example header for an esperanto translation of Ruby:
|
||||
Here's an example header for an Esperanto translation of Ruby:
|
||||
|
||||
```yaml
|
||||
---
|
||||
|
@ -1149,7 +1149,7 @@ my @list = 1, 3, 9 ... * > 30; # you can use a predicate
|
||||
# (with the Whatever Star, here).
|
||||
my @list = 1, 3, 9 ... { $_ > 30 }; # (equivalent to the above)
|
||||
|
||||
my @fib = 1, 1, *+* ... *; # lazy infinite list of prime numbers,
|
||||
my @fib = 1, 1, *+* ... *; # lazy infinite list of fibonacci series,
|
||||
# computed using a closure!
|
||||
my @fib = 1, 1, -> $a, $b { $a + $b } ... *; # (equivalent to the above)
|
||||
my @fib = 1, 1, { $^a + $^b } ... *; #(... also equivalent to the above)
|
||||
|
@ -7,21 +7,21 @@ contributors:
|
||||
filename: learnpython.py
|
||||
---
|
||||
|
||||
Python was created by Guido Van Rossum in the early 90's. 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 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]
|
||||
|
||||
Note: This article applies to Python 2.7 specifically, but should be applicable
|
||||
to Python 2.x. Look for another tour of Python 3 soon!
|
||||
to Python 2.x. For Python 3.x, take a look at the Python 3 tutorial.
|
||||
|
||||
```python
|
||||
|
||||
# Single line comments start with a number symbol.
|
||||
|
||||
""" Multiline strings can be written
|
||||
using three "'s, and are often used
|
||||
using three "s, and are often used
|
||||
as comments
|
||||
"""
|
||||
|
||||
@ -55,7 +55,7 @@ to Python 2.x. Look for another tour of Python 3 soon!
|
||||
# Modulo operation
|
||||
7 % 3 # => 1
|
||||
|
||||
# Exponentiation (x to the y'th power)
|
||||
# Exponentiation (x to the yth power)
|
||||
2**4 # => 16
|
||||
|
||||
# Enforce precedence with parentheses
|
||||
|
@ -7,7 +7,7 @@ contributors:
|
||||
filename: learnpython3.py
|
||||
---
|
||||
|
||||
Python was created by Guido Van Rossum in the early 90's. 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 most popular
|
||||
languages in existence. I fell in love with Python for its syntactic clarity. It's basically
|
||||
executable pseudocode.
|
||||
|
||||
@ -20,7 +20,7 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
|
||||
# Single line comments start with a number symbol.
|
||||
|
||||
""" Multiline strings can be written
|
||||
using three "'s, and are often used
|
||||
using three "s, and are often used
|
||||
as comments
|
||||
"""
|
||||
|
||||
@ -51,7 +51,7 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
|
||||
# Modulo operation
|
||||
7 % 3 # => 1
|
||||
|
||||
# Exponentiation (x to the y'th power)
|
||||
# Exponentiation (x to the yth power)
|
||||
2**4 # => 16
|
||||
|
||||
# Enforce precedence with parentheses
|
||||
|
@ -10,6 +10,7 @@ contributors:
|
||||
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
|
||||
- ["Ariel Krakowski", "http://www.learneroo.com"]
|
||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||
- ["Levi Bostian", "https://github.com/levibostian"]
|
||||
|
||||
---
|
||||
|
||||
@ -271,6 +272,19 @@ else
|
||||
end
|
||||
#=> "OK job"
|
||||
|
||||
# exception handling:
|
||||
begin
|
||||
# code here that might raise an exception
|
||||
raise NoMemoryError, 'You ran out of memory.'
|
||||
rescue NoMemoryError => exception_variable
|
||||
puts 'NoMemoryError was raised', exception_variable
|
||||
rescue RuntimeError => other_exception_variable
|
||||
puts 'RuntimeError was raised now'
|
||||
else
|
||||
puts 'This runs if no exceptions were thrown at all'
|
||||
ensure
|
||||
puts 'This code always runs no matter what'
|
||||
end
|
||||
|
||||
# Functions
|
||||
|
||||
|
@ -100,7 +100,7 @@ true == false // false
|
||||
|
||||
"Scala strings are surrounded by double quotes"
|
||||
'a' // A Scala Char
|
||||
'Single quote strings don't exist' // Error
|
||||
// 'Single quote strings don't exist' <= This causes an error
|
||||
|
||||
// Strings have the usual Java methods defined on them
|
||||
"hello world".length
|
||||
@ -204,6 +204,7 @@ def showNumbersInRange(a:Int, b:Int):Unit = {
|
||||
if (a < b)
|
||||
showNumbersInRange(a + 1, b)
|
||||
}
|
||||
showNumbersInRange(1,14)
|
||||
|
||||
|
||||
// Conditionals
|
||||
@ -218,9 +219,6 @@ if (x == 11) println ("yeah") else println("nay")
|
||||
println(if (x == 10) "yeah" else "nope")
|
||||
val text = if (x == 10) "yeah" else "nope"
|
||||
|
||||
var i = 0
|
||||
while (i < 10) { println("i " + i); i+=1 }
|
||||
|
||||
|
||||
#################################################
|
||||
## 4. Data Structures
|
||||
@ -292,7 +290,8 @@ d._2
|
||||
And now we will explain what these are.
|
||||
*/
|
||||
|
||||
class Dog {
|
||||
class Dog(br: String) {
|
||||
var breed: String = br
|
||||
//A method called bark, returning a String
|
||||
def bark: String = {
|
||||
// the body of the method
|
||||
@ -300,6 +299,11 @@ class Dog {
|
||||
}
|
||||
}
|
||||
|
||||
val mydog = new Dog("greyhound")
|
||||
println(mydog.breed) // => "greyhound"
|
||||
println(mydog.bark) // => "Woof, woof!"
|
||||
|
||||
|
||||
// Classes can contain nearly any other construct, including other classes,
|
||||
// functions, methods, objects, case classes, traits etc.
|
||||
|
||||
@ -388,6 +392,7 @@ sSquared.reduce (_+_)
|
||||
// The filter function takes a predicate (a function from A -> Boolean) and
|
||||
// selects all elements which satisfy the predicate
|
||||
List(1, 2, 3) filter (_ > 2) // List(3)
|
||||
case class Person(name:String, phoneNumber:String)
|
||||
List(
|
||||
Person(name = "Dom", age = 23),
|
||||
Person(name = "Bob", age = 30)
|
||||
@ -396,6 +401,7 @@ List(
|
||||
|
||||
// Scala a foreach method defined on certain collections that takes a type
|
||||
// returning Unit (a void method)
|
||||
val aListOfNumbers = List(1, 2, 3, 4, 10, 20, 100)
|
||||
aListOfNumbers foreach (x => println(x))
|
||||
aListOfNumbers foreach println
|
||||
|
||||
|
@ -6,7 +6,8 @@ contributors:
|
||||
- ["Andre Polykanine", "https://github.com/Oire"]
|
||||
translators:
|
||||
- ["Geoff Liu", "http://geoffliu.me"]
|
||||
filename: learnpython3.py
|
||||
filename: learnpython3-cn.py
|
||||
lang: zh-cn
|
||||
---
|
||||
|
||||
Python是由吉多·范罗苏姆(Guido Van Rossum)在90年代早期设计。它是如今最常用的编程
|
||||
|
Loading…
Reference in New Issue
Block a user