diff options
-rw-r--r-- | awk.html.markdown | 2 | ||||
-rw-r--r-- | dart.html.markdown | 2 | ||||
-rw-r--r-- | es-es/awk-es.html.markdown | 2 | ||||
-rw-r--r-- | fr-fr/awk-fr.html.markdown | 2 | ||||
-rw-r--r-- | go.html.markdown | 2 | ||||
-rw-r--r-- | haskell.html.markdown | 3 | ||||
-rw-r--r-- | java.html.markdown | 9 | ||||
-rw-r--r-- | javascript.html.markdown | 8 | ||||
-rw-r--r-- | jquery.html.markdown | 2 | ||||
-rw-r--r-- | kotlin.html.markdown | 2 | ||||
-rw-r--r-- | pt-br/awk-pt.html.markdown | 2 | ||||
-rw-r--r-- | python.html.markdown | 84 | ||||
-rw-r--r-- | rst.html.markdown | 2 | ||||
-rw-r--r-- | rust.html.markdown | 3 | ||||
-rw-r--r-- | xml.html.markdown | 2 | ||||
-rw-r--r-- | yaml.html.markdown | 4 | ||||
-rw-r--r-- | zh-cn/awk-cn.html.markdown | 2 | ||||
-rw-r--r-- | zh-cn/c-cn.html.markdown | 2 |
18 files changed, 90 insertions, 45 deletions
diff --git a/awk.html.markdown b/awk.html.markdown index dc22a2bd..e1d4a0a3 100644 --- a/awk.html.markdown +++ b/awk.html.markdown @@ -209,7 +209,7 @@ function string_functions( localvar, arr) { # Both return number of matches replaced localvar = "fooooobar"; sub("fo+", "Meet me at the ", localvar); # localvar => "Meet me at the bar" - gsub("e", ".", localvar); # localvar => "m..t m. at th. bar" + gsub("e", ".", localvar); # localvar => "M..t m. at th. bar" # Search for a string that matches a regular expression # index() does the same thing, but doesn't allow a regular expression diff --git a/dart.html.markdown b/dart.html.markdown index 69e1623d..282f183b 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -45,7 +45,7 @@ const CONSTANT_VALUE = "I CANNOT CHANGE"; CONSTANT_VALUE = "DID I?"; //Error /// Final is another variable declaration that cannot be change once it has been instantiated. Commonly used in classes and functions /// `final` can be declared in pascalCase. -final finalValue = "value cannot be change once instantiated"; +final finalValue = "value cannot be changed once instantiated"; finalValue = "Seems not"; //Error /// `var` is another variable declaration that is mutable and can change its value. Dart will infer types and will not change its data type diff --git a/es-es/awk-es.html.markdown b/es-es/awk-es.html.markdown index 725dae1d..1ee12956 100644 --- a/es-es/awk-es.html.markdown +++ b/es-es/awk-es.html.markdown @@ -196,7 +196,7 @@ function string_functions( localvar, arr) { # Ambas regresan el número de matches remplazados. localvar = "fooooobar" sub("fo+", "Meet me at the ", localvar) # localvar => "Meet me at the bar" - gsub("e", ".", localvar) # localvar => "m..t m. at th. bar" + gsub("e", ".", localvar) # localvar => "M..t m. at th. bar" # Buscar una cadena que haga match con una expresión regular # index() hace lo mismo, pero no permite expresiones regulares diff --git a/fr-fr/awk-fr.html.markdown b/fr-fr/awk-fr.html.markdown index a5db24b2..bd4e1312 100644 --- a/fr-fr/awk-fr.html.markdown +++ b/fr-fr/awk-fr.html.markdown @@ -217,7 +217,7 @@ function string_functions( localvar, arr) { # Les deux renvoient le nombre de correspondances remplacées localvar = "fooooobar"; sub("fo+", "Meet me at the ", localvar); # localvar => "Meet me at the bar" - gsub("e", ".", localvar); # localvar => "m..t m. at th. bar" + gsub("e", ".", localvar); # localvar => "M..t m. at th. bar" # Rechercher une chaîne de caractères qui correspond à une expression # régulière index() fait la même chose, mais n'autorise pas les expressions diff --git a/go.html.markdown b/go.html.markdown index fe69ed43..9dbfefaa 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -46,7 +46,7 @@ package main import ( "fmt" // A package in the Go standard library. "io/ioutil" // Implements some I/O utility functions. - "math" // Math library with local alias m. + m "math" // Math library with local alias m. "net/http" // Yes, a web server! "os" // OS functions like working with the file system "strconv" // String conversions. diff --git a/haskell.html.markdown b/haskell.html.markdown index 29712570..edb4121d 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -3,6 +3,7 @@ language: Haskell filename: learnhaskell.hs contributors: - ["Adit Bhargava", "http://adit.io"] + - ["Stanislav Modrak", "https://stanislav.gq"] --- Haskell was designed as a practical, purely functional programming @@ -602,6 +603,6 @@ qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater There are two popular ways to install Haskell: The traditional [Cabal-based installation](http://www.haskell.org/platform/), and the newer [Stack-based process](https://www.stackage.org/install). You can find a much gentler introduction from the excellent -[Learn you a Haskell](http://learnyouahaskell.com/), +[Learn you a Haskell](http://learnyouahaskell.com/) (or [up-to-date community version](https://learnyouahaskell.github.io/)), [Happy Learn Haskell Tutorial](http://www.happylearnhaskelltutorial.com/) or [Real World Haskell](http://book.realworldhaskell.org/). diff --git a/java.html.markdown b/java.html.markdown index 4be940be..10b2315b 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -91,6 +91,9 @@ public class LearnJava { int numInt = scanner.nextInt(); // read long input + long numLong = scanner.nextLong(); + + // read float input float numFloat = scanner.nextFloat(); // read double input @@ -314,7 +317,7 @@ public class LearnJava { System.out.println("1/2.0 = " + (i1 / (double)i2)); // => 0.5 // Modulo - System.out.println("11%3 = "+(11 % 3)); // => 2 + System.out.println("11%3 = " + (11 % 3)); // => 2 // Comparison operators System.out.println("3 == 2? " + (3 == 2)); // => false @@ -368,7 +371,7 @@ public class LearnJava { // While loop int fooWhile = 0; - while(fooWhile < 100) { + while (fooWhile < 100) { System.out.println(fooWhile); // Increment the counter // Iterated 100 times, fooWhile 0,1,2...99 @@ -383,7 +386,7 @@ public class LearnJava { // Increment the counter // Iterated 100 times, fooDoWhile 0->99 fooDoWhile++; - } while(fooDoWhile < 100); + } while (fooDoWhile < 100); System.out.println("fooDoWhile Value: " + fooDoWhile); // For Loop diff --git a/javascript.html.markdown b/javascript.html.markdown index 41ed7dea..cb530bbb 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -105,6 +105,10 @@ false; "1, 2, " + 3; // = "1, 2, 3" "Hello " + ["world", "!"]; // = "Hello world,!" +// ...which can result in some weird behaviour... +13 + !0; // 14 +"13" + !0; // '13true' + // and are compared with < and > "a" < "b"; // = true @@ -116,10 +120,6 @@ null == undefined; // = true "5" === 5; // = false null === undefined; // = false -// ...which can result in some weird behaviour... -13 + !0; // 14 -"13" + !0; // '13true' - // You can access characters in a string with `charAt` "This is a string".charAt(0); // = 'T' diff --git a/jquery.html.markdown b/jquery.html.markdown index 18077dca..cdcb89d9 100644 --- a/jquery.html.markdown +++ b/jquery.html.markdown @@ -12,8 +12,8 @@ jQuery is a JavaScript library that helps you "do more, write less". It makes ma Because jQuery is a JavaScript library you should [learn JavaScript first](https://learnxinyminutes.com/docs/javascript/) **NOTE**: jQuery has fallen out of the limelight in recent years, since you can achieve the same thing with the vanilla DOM (Document Object Model) API. So the only thing it is used for is a couple of handy features, such as the [jQuery date picker](https://api.jqueryui.com/datepicker) (which actually has a standard, unlike the `<input type="date">` HTML element), and the obvious decrease in the code length. -```js +```js /////////////////////////////////// // 1. Selectors diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 12008074..6ca2dcf2 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -297,7 +297,7 @@ fun helloWorld(val name : String) { else -> println("none of the above") } - // "when" can be used as a function that returns a value. + // "when" can be used as an expression that returns a value. var result = when (i) { 0, 21 -> "0 or 21" in 1..20 -> "in the range 1 to 20" diff --git a/pt-br/awk-pt.html.markdown b/pt-br/awk-pt.html.markdown index 597b0e7a..02bffc41 100644 --- a/pt-br/awk-pt.html.markdown +++ b/pt-br/awk-pt.html.markdown @@ -202,7 +202,7 @@ function string_functions( localvar, arr) { # Ambas retornam o número de instâncias substituídas localvar = "fooooobar" sub("fo+", "Meet me at the ", localvar) # localvar => "Meet me at the bar" - gsub("e", ".", localvar) # localvar => "m..t m. at th. bar" + gsub("e", ".", localvar) # localvar => "M..t m. at th. bar" # Localiza um texto que casa com uma expressão regular # index() faz a mesma coisa, mas não permite uma expressão regular diff --git a/python.html.markdown b/python.html.markdown index d9eda60c..326ddb95 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -685,8 +685,8 @@ print(math.sqrt(16)) # => 4.0 # You can get specific functions from a module from math import ceil, floor -print(ceil(3.7)) # => 4.0 -print(floor(3.7)) # => 3.0 +print(ceil(3.7)) # => 4 +print(floor(3.7)) # => 3 # You can import all functions from a module. # Warning: this is not recommended @@ -733,7 +733,9 @@ class Human: self.name = name # Initialize property - self._age = 0 + self._age = 0 # the leading underscore indicates the "age" property is + # intended to be used internally + # do not rely on this to be enforced: it's a hint to other devs # An instance method. All methods take "self" as the first argument def say(self, msg): @@ -876,7 +878,8 @@ if __name__ == '__main__': if type(sup) is Superhero: print('I am a superhero') - # Get the Method Resolution search Order used by both getattr() and super() + # Get the "Method Resolution Order" used by both getattr() and super() + # (the order in which classes are searched for an attribute or method) # This attribute is dynamic and can be updated print(Superhero.__mro__) # => (<class '__main__.Superhero'>, # => <class 'human.Human'>, <class 'object'>) @@ -958,8 +961,7 @@ class Batman(Superhero, Bat): if __name__ == '__main__': sup = Batman() - # Get the Method Resolution search Order used by both getattr() and super(). - # This attribute is dynamic and can be updated + # The Method Resolution Order print(Batman.__mro__) # => (<class '__main__.Batman'>, # => <class 'superhero.Superhero'>, # => <class 'human.Human'>, @@ -1016,31 +1018,67 @@ gen_to_list = list(values) print(gen_to_list) # => [-1, -2, -3, -4, -5] -# Decorators -# In this example `beg` wraps `say`. If say_please is True then it -# will change the returned message. -from functools import wraps +# Decorators are a form of syntactic sugar. +# They make code easier to read while accomplishing clunky syntax. +# Wrappers are one type of decorator. +# They're really useful for adding logging to existing functions without needing to modify them. -def beg(target_function): - @wraps(target_function) +def log_function(func): def wrapper(*args, **kwargs): - msg, say_please = target_function(*args, **kwargs) - if say_please: - return "{} {}".format(msg, "Please! I am poor :(") - return msg - + print("Entering function", func.__name__) + result = func(*args, **kwargs) + print("Exiting function", func.__name__) + return result return wrapper +@log_function # equivalent: +def my_function(x,y): # def my_function(x,y): + return x+y # return x+y + # my_function = log_function(my_function) +# The decorator @log_function tells us as we begin reading the function definition +# for my_function that this function will be wrapped with log_function. +# When function definitions are long, it can be hard to parse the non-decorated +# assignment at the end of the definition. + +my_function(1,2) # => "Entering function my_function" + # => "3" + # => "Exiting function my_function" + +# But there's a problem. +# What happens if we try to get some information about my_function? + +print(my_function.__name__) # => 'wrapper' +print(my_function.__code__.co_argcount) # => 0. The argcount is 0 because both arguments in wrapper()'s signature are optional. + +# Because our decorator is equivalent to my_function = log_function(my_function) +# we've replaced information about my_function with information from wrapper + +# Fix this using functools + +from functools import wraps + +def log_function(func): + @wraps(func) # this ensures docstring, function name, arguments list, etc. are all copied + # to the wrapped function - instead of being replaced with wrapper's info + def wrapper(*args, **kwargs): + print("Entering function", func.__name__) + result = func(*args, **kwargs) + print("Exiting function", func.__name__) + return result + return wrapper -@beg -def say(say_please=False): - msg = "Can you buy me a beer?" - return msg, say_please +@log_function +def my_function(x,y): + return x+y + +my_function(1,2) # => "Entering function my_function" + # => "3" + # => "Exiting function my_function" +print(my_function.__name__) # => 'my_function' +print(my_function.__code__.co_argcount) # => 2 -print(say()) # Can you buy me a beer? -print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :( ``` ### Free Online diff --git a/rst.html.markdown b/rst.html.markdown index c177fdb4..8a730c7a 100644 --- a/rst.html.markdown +++ b/rst.html.markdown @@ -8,7 +8,7 @@ filename: restructuredtext.rst RST, Restructured Text, is a file format created by the Python community to write documentation. It is part of [Docutils](https://docutils.sourceforge.io/rst.html). -RST is a markdown language like HTML but is much more lightweight and easier to read. +RST is a markup language like HTML but is much more lightweight and easier to read. ## Installation diff --git a/rust.html.markdown b/rust.html.markdown index c677ed96..526d20d5 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -30,6 +30,9 @@ Rust not only fast, but also easy and efficient to code in. // This is a comment. Line comments look like this... // and extend multiple lines like this. +/* Block comments + /* can be nested. */ */ + /// Documentation comments look like this and support markdown notation. /// # Examples /// diff --git a/xml.html.markdown b/xml.html.markdown index 2a258d94..630e4c90 100644 --- a/xml.html.markdown +++ b/xml.html.markdown @@ -165,7 +165,7 @@ Support for DTDs is ubiquitous because they are so old. Unfortunately, modern XM ## Further Reading -* [XML Schema Definitions Tutorial](http://www.w3schools.com/schema/) +* [XML Schema Definitions Tutorial](https://www.w3schools.com/xml/schema_intro.asp) * [DTD Tutorial](http://www.w3schools.com/xml/xml_dtd_intro.asp) * [XML Tutorial](http://www.w3schools.com/xml/default.asp) * [Using XPath queries to parse XML](http://www.w3schools.com/xml/xml_xpath.asp) diff --git a/yaml.html.markdown b/yaml.html.markdown index 135213d2..2bb35d42 100644 --- a/yaml.html.markdown +++ b/yaml.html.markdown @@ -44,8 +44,8 @@ key with spaces: value # Yes and No (doesn't matter the case) will be evaluated to boolean # true and false values respectively. # To use the actual value use single or double quotes. -no: no # evaluates to "false": false -yes: No # evaluates to "true": false +no: no # evaluates to "no": false +yes: No # evaluates to "yes": false not_enclosed: yes # evaluates to "not_enclosed": true enclosed: "yes" # evaluates to "enclosed": yes diff --git a/zh-cn/awk-cn.html.markdown b/zh-cn/awk-cn.html.markdown index bac833a6..02f1f7d5 100644 --- a/zh-cn/awk-cn.html.markdown +++ b/zh-cn/awk-cn.html.markdown @@ -179,7 +179,7 @@ function string_functions( localvar, arr) { # 都是返回替换的个数 localvar = "fooooobar" sub("fo+", "Meet me at the ", localvar) # localvar => "Meet me at the bar" - gsub("e", ".", localvar) # localvar => "m..t m. at th. bar" + gsub("e", ".", localvar) # localvar => "M..t m. at th. bar" # 搜索匹配正则的字符串 # index() 也是搜索, 不支持正则 diff --git a/zh-cn/c-cn.html.markdown b/zh-cn/c-cn.html.markdown index dd4445f7..851f2981 100644 --- a/zh-cn/c-cn.html.markdown +++ b/zh-cn/c-cn.html.markdown @@ -474,7 +474,7 @@ void testFunc() { // 用户自定义类型和结构 /////////////////////////////////////// -// Typedefs可以创建类型别名 +// typedef 可以创建类型别名 typedef int my_type; my_type my_type_var = 0; |