From 28fcbc8e1c7d22bbc192418b4f3513f2ca4ead3e Mon Sep 17 00:00:00 2001 From: Louie Dinh Date: Tue, 23 Dec 2014 11:23:22 -0800 Subject: Fix typo --- python.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 53381f32..da04d381 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -264,7 +264,7 @@ filled_dict.get("four") # => None # The get method supports a default argument when the value is missing filled_dict.get("one", 4) # => 1 filled_dict.get("four", 4) # => 4 -# note that filled_dict.get("four") is still => 4 +# note that filled_dict.get("four") is still => None # (get doesn't set the value in the dictionary) # set the value of a key with a syntax similar to lists -- cgit v1.2.3 From 22a0f44e64e6c7ac969556b9648ebcfca4bad187 Mon Sep 17 00:00:00 2001 From: suuuzi Date: Wed, 4 Feb 2015 15:36:20 -0200 Subject: Refering Python3 tutorial link --- python.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index da04d381..478804cd 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -14,7 +14,7 @@ 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. For Python 3.x, take a look at the Python 3 tutorial. +to Python 2.x. For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/). ```python -- cgit v1.2.3 From 2ad26dd44a9129aade696ac64d9d6ae1a1f6a98b Mon Sep 17 00:00:00 2001 From: Sriram Sundarraj Date: Thu, 23 Apr 2015 01:30:40 +0530 Subject: [python/en] Adding strings without + added. --- python.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 478804cd..63547bf6 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -101,6 +101,8 @@ not False # => True # Strings can be added too! "Hello " + "world!" # => "Hello world!" +# Strings can be added without using '+' +"Hello " "world!" # => "Hello world!" # ... or multiplied "Hello" * 3 # => "HelloHelloHello" -- cgit v1.2.3 From 98aa4ef43c84b9bdaa988971174bbb21e042e6ac Mon Sep 17 00:00:00 2001 From: Sriram Sundarraj Date: Fri, 24 Apr 2015 01:50:17 +0530 Subject: [python/en] Added range(start, stop). --- python.html.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 63547bf6..668e04f9 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -346,6 +346,18 @@ prints: for i in range(4): print(i) +""" +"range(lower, upper)" returns a list of numbers +from the lower number to the upper number +prints: + 4 + 5 + 6 + 7 +""" +for i in range(4, 8): + print(i) + """ While loops go until a condition is no longer met. prints: -- cgit v1.2.3 From 6b6342a7dc8d4280eb4465894bc15cdd5b7ff383 Mon Sep 17 00:00:00 2001 From: Sriram Sundarraj Date: Fri, 24 Apr 2015 22:57:33 +0530 Subject: [python/en] Moved to default python2 print statements. --- python.html.markdown | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 668e04f9..899a97f8 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -145,8 +145,10 @@ bool("") # => False print "I'm Python. Nice to meet you!" # Python also has a print function, available in versions 2.7 and 3... # but for 2.7 you need to add the import (uncommented): -# from __future__ import print_function +from __future__ import print_function print("I'm also Python! ") +# This is useful to maintain compatibility, +# but for this doc, we'll use the python 2 print statement # No need to declare variables before assigning to them. some_var = 5 # Convention is to use lower_case_with_underscores @@ -316,11 +318,11 @@ some_var = 5 # Here is an if statement. Indentation is significant in python! # prints "some_var is smaller than 10" if some_var > 10: - print("some_var is totally bigger than 10.") + print "some_var is totally bigger than 10." elif some_var < 10: # This elif clause is optional. - print("some_var is smaller than 10.") + print "some_var is smaller than 10." else: # This is optional too. - print("some_var is indeed 10.") + print "some_var is indeed 10." """ @@ -332,7 +334,7 @@ prints: """ for animal in ["dog", "cat", "mouse"]: # You can use % to interpolate formatted strings - print("%s is a mammal" % animal) + print "%s is a mammal" % animal """ "range(number)" returns a list of numbers @@ -344,7 +346,7 @@ prints: 3 """ for i in range(4): - print(i) + print i """ "range(lower, upper)" returns a list of numbers @@ -356,7 +358,7 @@ prints: 7 """ for i in range(4, 8): - print(i) + print i """ While loops go until a condition is no longer met. @@ -368,7 +370,7 @@ prints: """ x = 0 while x < 4: - print(x) + print x x += 1 # Shorthand for x = x + 1 # Handle exceptions with a try/except block @@ -391,7 +393,7 @@ else: # Optional clause to the try/except block. Must follow all except blocks # Use "def" to create new functions def add(x, y): - print("x is %s and y is %s" % (x, y)) + print "x is %s and y is %s" % (x, y) return x + y # Return values with a return statement # Calling functions with parameters @@ -420,8 +422,8 @@ keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"} # You can do both at once, if you like def all_the_args(*args, **kwargs): - print(args) - print(kwargs) + print args + print kwargs """ all_the_args(1, 2, a=3, b=4) prints: (1, 2) @@ -517,10 +519,10 @@ class Human(object): # Instantiate a class i = Human(name="Ian") -print(i.say("hi")) # prints out "Ian: hi" +print i.say("hi") # prints out "Ian: hi" j = Human("Joel") -print(j.say("hello")) # prints out "Joel: hello" +print j.say("hello") # prints out "Joel: hello" # Call our class method i.get_species() # => "H. sapiens" @@ -540,12 +542,12 @@ Human.grunt() # => "*grunt*" # You can import modules import math -print(math.sqrt(16)) # => 4 +print math.sqrt(16) # => 4 # 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.0 +print floor(3.7) # => 3.0 # You can import all functions from a module. # Warning: this is not recommended @@ -591,7 +593,7 @@ xrange_ = xrange(1, 900000000) # will double all numbers until a result >=30 found for i in double_numbers(xrange_): - print(i) + print i if i >= 30: break @@ -620,8 +622,8 @@ def say(say_please=False): 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 :( +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? -- cgit v1.2.3 From c2963cdc31ea9c0cce9d5abf8b0a6d606d11b3a0 Mon Sep 17 00:00:00 2001 From: Sriram Sundarraj Date: Fri, 24 Apr 2015 23:29:01 +0530 Subject: [python/en] Removed python3 print. --- python.html.markdown | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 899a97f8..7281a330 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -141,14 +141,8 @@ bool("") # => False ## 2. Variables and Collections #################################################### -# Python has a print statement, in all 2.x versions but removed from 3. +# Python has a print statement print "I'm Python. Nice to meet you!" -# Python also has a print function, available in versions 2.7 and 3... -# but for 2.7 you need to add the import (uncommented): -from __future__ import print_function -print("I'm also Python! ") -# This is useful to maintain compatibility, -# but for this doc, we'll use the python 2 print statement # No need to declare variables before assigning to them. some_var = 5 # Convention is to use lower_case_with_underscores -- cgit v1.2.3 From e13e00945dc4bb20c7cf6b9cd4af87f73b965ddb Mon Sep 17 00:00:00 2001 From: Rinoc Johnson Date: Thu, 30 Apr 2015 17:56:01 -0400 Subject: Fix Python typo. --- python.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 7281a330..f081a6a7 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -46,7 +46,7 @@ to Python 2.x. For Python 3.x, take a look at the [Python 3 tutorial](http://lea 2.0 # This is a float 11.0 / 4.0 # => 2.75 ahhh...much better -# Result of integer division truncated down both for positive and negative. +# Result of integer division truncated down both for positive and negative. 5 // 3 # => 1 5.0 // 3.0 # => 1.0 # works on floats too -5 // 3 # => -2 @@ -191,7 +191,7 @@ li[2:] # => [4, 3] li[:3] # => [1, 2, 4] # Select every second entry li[::2] # =>[1, 4] -# Revert the list +# Reverse the list li[::-1] # => [3, 4, 2, 1] # Use any combination of these to make advanced slices # li[start:end:step] @@ -439,14 +439,14 @@ def pass_all_the_args(*args, **kwargs): print varargs(*args) print keyword_args(**kwargs) -# Function Scope +# Function Scope x = 5 def setX(num): # Local var x not the same as global variable x x = num # => 43 print x # => 43 - + def setGlobalX(num): global x print x # => 5 -- cgit v1.2.3 From 5ebe2dcb6eeaf7e34daf07f76dcfa2403f05a332 Mon Sep 17 00:00:00 2001 From: Rinoc Johnson Date: Thu, 30 Apr 2015 19:31:38 -0400 Subject: Clarify wording for list reversal. --- python.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index f081a6a7..ace3f794 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -191,14 +191,14 @@ li[2:] # => [4, 3] li[:3] # => [1, 2, 4] # Select every second entry li[::2] # =>[1, 4] -# Reverse the list +# Reverse a copy of the list li[::-1] # => [3, 4, 2, 1] # Use any combination of these to make advanced slices # li[start:end:step] # Remove arbitrary elements from a list with "del" del li[2] # li is now [1, 2, 3] - +r # You can add lists li + other_li # => [1, 2, 3, 4, 5, 6] # Note: values for li and for other_li are not modified. -- cgit v1.2.3