Tutorial by Examples: at

Python's string type provides many functions that act on the capitalization of a string. These include : str.casefold str.upper str.lower str.capitalize str.title str.swapcase With unicode strings (the default in Python 3), these operations are not 1:1 mappings or reversible. Most of thes...
In the following example - Database for an auto shop business, we have a list of departments, employees, customers and customer cars. We are using foreign keys to create relationships between the various tables. Live example: SQL fiddle Relationships between tables Each Department may have 0 ...
A generator function is created with a function* declaration. When it is called, its body is not immediately executed. Instead, it returns a generator object, which can be used to "step through" the function's execution. A yield expression inside the function body defines a point at which...
A generator is iterable. It can be looped over with a for...of statement, and used in other constructs which depend on the iteration protocol. function* range(n) { for (let i = 0; i < n; ++i) { yield i; } } // looping for (let n of range(10)) { // n takes on the valu...
It is possible to send a value to the generator by passing it to the next() method. function* summer() { let sum = 0, value; while (true) { // receive sent value value = yield; if (value === null) break; // aggregate values sum += value; ...
A hash in Ruby is an object that implements a hash table, mapping keys to values. Ruby supports a specific literal syntax for defining hashes using {}: my_hash = {} # an empty hash grades = { 'Mark' => 15, 'Jimmy' => 10, 'Jack' => 10 } A hash can also be created using the standard new...
When the commits on two branches don't conflict, Git can automatically merge them: ~/Stack Overflow(branch:master) » git merge another_branch Auto-merging file_a Merge made by the 'recursive' strategy. file_a | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
A generator object supports the iterator protocol. That is, it provides a next() method (__next__() in Python 3.x), which is used to step through its execution, and its __iter__ method returns itself. This means that a generator can be used in any language construct which supports generic iterable o...
In addition to receiving values from a generator, it is possible to send an object to a generator using the send() method. def accumulator(): total = 0 value = None while True: # receive sent value value = yield total if value is None: break # aggr...
It's possible to create generator iterators using a comprehension-like syntax. generator = (i * 2 for i in range(3)) next(generator) # 0 next(generator) # 2 next(generator) # 4 next(generator) # raises StopIteration If a function doesn't necessarily need to be passed a list, you can sa...
a, b = 2, 3 a * b # = 6 import operator operator.mul(a, b) # = 6 Possible combinations (builtin types): int and int (gives an int) int and float (gives a float) int and complex (gives a complex) float and float (gives a float) float and complex (gives a comple...
a, b = 2, 3 (a ** b) # = 8 pow(a, b) # = 8 import math math.pow(a, b) # = 8.0 (always float; does not allow complex results) import operator operator.pow(a, b) # = 8 Another difference between the built-in pow and math.pow is that the built-in po...
A practical use case of a generator is to iterate through values of an infinite series. Here's an example of finding the first ten terms of the Fibonacci Sequence. def fib(a=0, b=1): """Generator that yields Fibonacci numbers. `a` and `b` are the seed values""" ...
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 delegate is a common design pattern used in Cocoa and CocoaTouch frameworks, where one class delegates responsibility for implementing some functionality to another. This follows a principle of separation of concerns, where the framework class implements generic functionality while a separate dele...
The C language has three mandatory real floating point types, float, double, and long double. float f = 0.314f; /* suffix f or F denotes type float */ double d = 0.314; /* no suffix denotes double */ long double ld = 0.314l; /* suffix l or L denotes long double */ /* the differen...
Syntax : history.replaceState(data, title [, url ]) This method modifies the current history entry instead of creating a new one. Mainly used when we want to update URL of the current history entry. window.history.replaceState("http://example.ca", "Sample Title", "/exam...
Syntax : history.pushState(state object, title, url) This method allows to ADD histories entries. For more reference, Please have a look on this document : pushState() method Example : window.history.pushState("http://example.ca", "Sample Title", "/example/path.html&qu...
With a Frame When you know the exact dimensions you want to set for your label, you can initialize a UILabel with a CGRect frame. Swift let frame = CGRect(x: 0, y: 0, width: 200, height: 21) let label = UILabel(frame: frame) view.addSubview(label) Objective-C CGRect frame = CGRectMake(0, 0,...
Use new Date() to generate a new Date object containing the current date and time. Note that Date() called without arguments is equivalent to new Date(Date.now()). Once you have a date object, you can apply any of the several available methods to extract its properties (e.g. getFullYear() to get t...

Page 10 of 442