summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--csharp.html.markdown8
-rw-r--r--python.html.markdown48
-rw-r--r--zh-cn/c-cn.html.markdown4
3 files changed, 54 insertions, 6 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 12bdf168..81b50e08 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -106,7 +106,7 @@ namespace Learning
Console.WriteLine(fooString);
// You can access each character of the string with an indexer:
- char charFromString = fooString[1]; // 'y'
+ char charFromString = fooString[1]; // => 'e'
// Strings are immutable: you can't do fooString[1] = 'X';
// Compare strings with current culture, ignoring case
@@ -174,7 +174,7 @@ on a new line! ""Wow!"", the masses cried";
int i1 = 1, i2 = 2; // Shorthand for multiple declarations
// Arithmetic is straightforward
- Console.WriteLine(i1 + i2 - i1 * 3 / 7); //
+ Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3
// Modulo
Console.WriteLine("11%3 = " + (11 % 3)); // => 2
@@ -242,7 +242,7 @@ on a new line! ""Wow!"", the masses cried";
int fooDoWhile = 0;
do
{
- //Iterated 99 times, fooDoWhile 0->99
+ //Iterated 100 times, fooDoWhile 0->99
fooDoWhile++;
} while (fooDoWhile < 100);
@@ -588,7 +588,7 @@ on a new line! ""Wow!"", the masses cried";
AIST,
BMC,
Electra = 42, //you can explicitly set a value to a name
- Gitane
+ Gitane // 43
}
// We defined this type inside a Bicycle class, so it is a nested type
// Code outside of this class should reference this type as Bicycle.Brand
diff --git a/python.html.markdown b/python.html.markdown
index 941ba9f4..15f27d37 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -473,6 +473,54 @@ import math
dir(math)
+####################################################
+## 7. Advanced
+####################################################
+
+# Generators help you make lazy code
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# generator creates the value on the fly
+# instead of generating and returning all values at once it creates one in each iteration
+# this means values bigger than 15 wont be processed in double_numbers
+# note range is a generator too, creating a list 1-900000000 would take lot of time to be made
+_range = range(1, 900000000)
+# will double all numbers until a result >=30 found
+for i in double_numbers(_range):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Decorators
+# in this example beg wraps say
+# Beg will call say. If say_please is True then it will change the returned message
+from functools import wraps
+
+
+def beg(_say):
+ @wraps(_say)
+ def wrapper(*args, **kwargs):
+ msg, say_please = _say(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, "Please! I am poor :(")
+ return msg
+
+ 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 :(
+
+
```
## Ready For More?
diff --git a/zh-cn/c-cn.html.markdown b/zh-cn/c-cn.html.markdown
index ecd2558e..223f6e35 100644
--- a/zh-cn/c-cn.html.markdown
+++ b/zh-cn/c-cn.html.markdown
@@ -331,8 +331,8 @@ printf("%d\n", (char)100.0);
///////////////////////////////////////
// 指针变量是用来储存内存地址的变量
-// 指针变量的声明也会告诉它所指向的数据的类型
-// 你可以得到你的变量的地址,并对它们搞乱。
+// 指针变量的声明也会告诉它所指向的数据的类型
+// 你可以使用得到你的变量的地址,并把它们搞乱,;-)
int x = 0;
printf("%p\n", &x); // 用 & 来获取变量的地址