2.0
array = %i(one two three four)
Creates the array [:one, :two, :three, :four].
Instead of %i(...), you may use %i{...} or %i[...] or %i!...!
Additionally, if you want to use interpolation, you can do this with %I.
2.0
a = 'hello'
b = 'goodbye'
array_one = %I(#{a} #{b} world)
array_tw...
This is the basic use of the <a> (anchor element) element:
<a href="http://example.com/">Link to example.com</a>
It creates a hyperlink, to the URL http://example.com/ as specified by the href (hypertext reference) attribute, with the anchor text "Link to example...
If you ignore files by using a pattern but have exceptions, prefix an exclamation mark(!) to the exception. For example:
*.txt
!important.txt
The above example instructs Git to ignore all files with the .txt extension except for files named important.txt.
If the file is in an ignored folder, y...
struct Repository {
let identifier: Int
let name: String
var description: String?
}
This defines a Repository struct with three stored properties, an integer identifier, a string name, and an optional string description. The identifier and name are constants, as they've been decla...
Relational operators check if a specific relation between two operands is true. The result is evaluated to 1 (which means true) or 0 (which means false). This result is often used to affect control flow (via if, while, for), but can also be stored in variables.
Equals "=="
Checks whether...
Assigns the value of the right-hand operand to the storage location named by the left-hand operand, and returns the value.
int x = 5; /* Variable x holds the value 5. Returns 5. */
char y = 'c'; /* Variable y holds the value 99. Returns 99
* (as the character 'c' is repr...
Basic Arithmetic
Return a value that is the result of applying the left hand operand to the right hand operand, using the associated mathematical operation. Normal mathematical rules of commutation apply (i.e. addition and multiplication are commutative, subtraction, division and modulus are not).
...
Logical AND
Performs a logical boolean AND-ing of the two operands returning 1 if both of the operands are non-zero. The logical AND operator is of type int.
0 && 0 /* Returns 0. */
0 && 1 /* Returns 0. */
2 && 0 /* Returns 0. */
2 && 3 /* Returns 1. */
Lo...
Getting the minimum or maximum or using sorted depends on iterations over the object. In the case of dict, the iteration is only over the keys:
adict = {'a': 3, 'b': 5, 'c': 1}
min(adict)
# Output: 'a'
max(adict)
# Output: 'c'
sorted(adict)
# Output: ['a', 'b', 'c']
To keep the dictionary ...
Getting the minimum of a sequence (iterable) is equivalent of accessing the first element of a sorted sequence:
min([2, 7, 5])
# Output: 2
sorted([2, 7, 5])[0]
# Output: 2
The maximum is a bit more complicated, because sorted keeps order and max returns the first encountered value. In case th...
For every infix operator, e.g. + there is a operator-function (operator.add for +):
1 + 1
# Output: 2
from operator import add
add(1, 1)
# Output: 2
even though the main documentation states that for the arithmetic operators only numerical input is allowed it is possible:
from operator impo...
The Promise.all() static method accepts an iterable (e.g. an Array) of promises and returns a new promise, which resolves when all promises in the iterable have resolved, or rejects if at least one of the promises in the iterable have rejected.
// wait "millis" ms, then resolve with "...
The Promise.race() static method accepts an iterable of Promises and returns a new Promise which resolves or rejects as soon as the first of the promises in the iterable has resolved or rejected.
// wait "milliseconds" milliseconds, then resolve with "value"
function resolve(va...
Arguments are defined in parentheses after the function name:
def divide(dividend, divisor): # The names of the function and its arguments
# The arguments are available by name in the body of the function
print(dividend / divisor)
The function name and its list of arguments are called...
Optional arguments can be defined by assigning (using =) a default value to the argument-name:
def make(action='nothing'):
return action
Calling this function is possible in 3 different ways:
make("fun")
# Out: fun
make(action="sleep")
# Out: sleep
# The argumen...
One can give a function as many arguments as one wants, the only fixed rules are that each argument name must be unique and that optional arguments must be after the not-optional ones:
def func(value1, value2, optionalvalue=10):
return '{0} {1} {2}'.format(value1, value2, optionalvalue1)
Wh...
Arbitrary number of positional arguments:
Defining a function capable of taking an arbitrary number of arguments can be done by prefixing one of the arguments with a *
def func(*args):
# args will be a tuple containing all values that are passed in
for i in args:
print(i)
fun...
A basic join (also called "inner join") queries data from two tables, with their relationship defined in a join clause.
The following example will select employees' first names (FName) from the Employees table and the name of the department they work for (Name) from the Departments table:...