From 3ffb8256ae007b55df71f63de66428b51f64a003 Mon Sep 17 00:00:00 2001 From: Meisyarah Dwiastuti Date: Tue, 31 Oct 2017 09:54:09 +0100 Subject: Add data type checking examples --- python.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 946cbc0c..89fa7046 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -363,6 +363,12 @@ filled_set | other_set # => {1, 2, 3, 4, 5, 6} # Check for existence in a set with in 2 in filled_set # => True 10 in filled_set # => False +10 not in filled_set # => True + +# Check data type of variable +type(li) # => list +type(filled_dict) # => dict +type(5) # => int #################################################### -- cgit v1.2.3 From 60fcfe86621980a2f98d19fee386c1d0cc4f61db Mon Sep 17 00:00:00 2001 From: Rommel Martinez Date: Sat, 3 Feb 2018 17:28:21 +0800 Subject: [python/en]: fix typo --- python.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 89fa7046..df1ca6f2 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -7,6 +7,7 @@ contributors: - ["evuez", "http://github.com/evuez"] - ["asyne", "https://github.com/justblah"] - ["habi", "http://github.com/habi"] + - ["Rommel Martinez", "https://ebzzry.io"] filename: learnpython.py --- @@ -508,9 +509,9 @@ all_the_args(1, 2, a=3, b=4) prints: # Use * to expand positional args and use ** to expand keyword args. args = (1, 2, 3, 4) kwargs = {"a": 3, "b": 4} -all_the_args(*args) # equivalent to foo(1, 2, 3, 4) -all_the_args(**kwargs) # equivalent to foo(a=3, b=4) -all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4) +all_the_args(*args) # equivalent to all_the_args(1, 2, 3, 4) +all_the_args(**kwargs) # equivalent to all_the_args(a=3, b=4) +all_the_args(*args, **kwargs) # equivalent to all_the_args(1, 2, 3, 4, a=3, b=4) # you can pass args and kwargs along to other functions that take args/kwargs -- cgit v1.2.3 From fa9f9fd5639458b7865a48192c4dc18e7ef15d66 Mon Sep 17 00:00:00 2001 From: Anindya Srivastava Date: Fri, 1 Feb 2019 21:55:22 +0530 Subject: Type correction for the output of math.sqrt() Both in Python 2.7.10 and Python 3.6.5, math.sqrt() returns a float and not int. It seems like a tiny thing but sometimes may lead up to bigger confusions. For example: https://stackoverflow.com/questions/54474037/why-are-the-following-codes-giving-me-different-output-square-root-big-numbers/54475501#54475501 --- 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 df1ca6f2..651927a7 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -661,7 +661,7 @@ i.age # => raises an AttributeError # You can import modules import math -print math.sqrt(16) # => 4 +print math.sqrt(16) # => 4.0 # You can get specific functions from a module from math import ceil, floor -- cgit v1.2.3 From cbcb987c53ad68e12326c5f7994fc7cfde028a18 Mon Sep 17 00:00:00 2001 From: Streppel Date: Sat, 16 Feb 2019 16:07:14 -0200 Subject: [python/py3] Updating set info (#3473) Updating set info to be more descriptive and informative --- python.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python.html.markdown') diff --git a/python.html.markdown b/python.html.markdown index 651927a7..0cc33a80 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -328,7 +328,8 @@ filled_dict["four"] = 4 # now, filled_dict["four"] => 4 filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5 filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5 -# Sets store ... well sets (which are like lists but can contain no duplicates) +# You can declare sets (which are like unordered lists that cannot contain +# duplicate values) using the set object. empty_set = set() # Initialize a "set()" with a bunch of values some_set = set([1, 2, 2, 3, 4]) # some_set is now set([1, 2, 3, 4]) -- cgit v1.2.3