Tutorial by Examples: al

SELECT PhoneNumber, Email, PreferredContact FROM Customers This statement will return the columns PhoneNumber, Email, and PreferredContact from all rows of the Customers table. Also the columns will be returned in the sequence in which they appear in the SELECT clause. The re...
Individual values of a hash are read and written using the [] and []= methods: my_hash = { length: 4, width: 5 } my_hash[:length] #=> => 4 my_hash[:height] = 9 my_hash #=> {:length => 4, :width => 5, :height => 9 } By default, accessing a key which has not been added t...
By default, attempting to lookup the value for a key which does not exist will return nil. You can optionally specify some other value to return (or an action to take) when the hash is accessed with a non-existent key. Although this is referred to as "the default value", it need not be a s...
A quick way to make a copy of an array (as opposed to assigning a variable with another reference to the original array) is: arr[:] Let's examine the syntax. [:] means that start, end, and slice are all omitted. They default to 0, len(arr), and 1, respectively, meaning that subarray that we are ...
An external CSS stylesheet can be applied to any number of HTML documents by placing a <link> element in each HTML document. The attribute rel of the <link> tag has to be set to "stylesheet", and the href attribute to the relative or absolute path to the stylesheet. While usin...
Python provides string interpolation and formatting functionality through the str.format function, introduced in version 2.6 and f-strings introduced in version 3.6. Given the following variables: i = 10 f = 1.5 s = "foo" l = ['a', 1, 2] d = {'a': 1, 2: 'foo'} The following statem...
A string literal in C is a sequence of chars, terminated by a literal zero. char* str = "hello, world"; /* string literal */ /* string literals can be used to initialize arrays */ char a1[] = "abc"; /* a1 is char[4] holding {'a','b','c','\0'} */ char a2[4] = "abc"...
A value in a Dictionary can be accessed using its key: var books: [Int: String] = [1: "Book 1", 2: "Book 2"] let bookName = books[1] //bookName = "Book 1" The values of a dictionary can be iterated through using the values property: for book in books.values { ...
Swift label.textAlignment = NSTextAlignment.left //or the shorter label.textAlignment = .left Any value in the NSTextAlignment enum is valid: .left, .center, .right, .justified, .natural Objective-C label.textAlignment = NSTextAlignmentLeft; Any value in the NSTextAlignment enum is vali...
class adder(object): def __init__(self, first): self.first = first # a(...) def __call__(self, second): return self.first + second add2 = adder(2) add2(1) # 3 add2(2) # 4
This example uses the Cars Table from the Example Databases. UPDATE Cars SET Status = 'READY' This statement will set the 'status' column of all rows of the 'Cars' table to "READY" because it does not have a WHERE clause to filter the set of rows.
This example uses the Cars Table from the Example Databases. UPDATE Cars SET TotalCost = TotalCost + 100 WHERE Id = 3 or Id = 4 Update operations can include current values in the updated row. In this simple example the TotalCost is incremented by 100 for two rows: The TotalCost of Car #3 i...
The general syntax for declaring a one-dimensional array is type arrName[size]; where type could be any built-in type or user-defined types such as structures, arrName is a user-defined identifier, and size is an integer constant. Declaring an array (an array of 10 int variables in this case) i...
Accessing array values is generally done through square brackets: int val; int array[10]; /* Setting the value of the fifth element to 5: */ array[4] = 5; /* The above is equal to: */ *(array + 4) = 5; /* Reading the value of the fifth element: */ val = array[4]; As a side effect of...
String literals in Swift are delimited with double quotes ("): let greeting = "Hello!" // greeting's type is String Characters can be initialized from string literals, as long as the literal contains only one grapheme cluster: let chr: Character = "H" // valid let chr...
Extensions can contain convenience initializers. For example, a failable initializer for Int that accepts a NSString: extension Int { init?(_ string: NSString) { self.init(string as String) // delegate to the existing Int.init(String) initializer } } let str1: NSString = &qu...
reduce will not terminate the iteration before the iterable has been completly iterated over so it can be used to create a non short-circuit any() or all() function: import operator # non short-circuit "all" reduce(operator.and_, [False, True, True, True]) # = False # non short-circu...
# First falsy element or last element if all are truthy: reduce(lambda i, j: i and j, [100, [], 20, 10]) # = [] reduce(lambda i, j: i and j, [100, 50, 20, 10]) # = 10 # First truthy element or last element if all falsy: reduce(lambda i, j: i or j, [100, [], 20, 0]) # = 100 reduce(la...
For example, you can take the absolute value of each element: list(map(abs, (1, -1, 2, -2, 3, -3))) # the call to `list` is unnecessary in 2.x # Out: [1, 1, 2, 2, 3, 3] Anonymous function also support for mapping a list: map(lambda x:x*2, [1, 2, 3, 4, 5]) # Out: [2, 4, 6, 8, 10] or convert...
For example calculating the average of each i-th element of multiple iterables: def average(*args): return float(sum(args)) / len(args) # cast to float - only mandatory for python 2.x measurement1 = [100, 111, 99, 97] measurement2 = [102, 117, 91, 102] measurement3 = [104, 102, 95, 101] ...

Page 8 of 269