Tutorial by Examples: co

You can compare multiple items with multiple comparison operators with chain comparison. For example x > y > z is just a short form of: x > y and y > z This will evaluate to True only if both comparisons are True. The general form is a OP b OP c OP d ... Where OP represents ...
Arrays can be created by enclosing a list of elements in square brackets ([ and ]). Array elements in this notation are separated with commas: array = [1, 2, 3, 4] Arrays can contain any kind of objects in any combination with no restrictions on type: array = [1, 'b', nil, [3, 4]]
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). ...
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 &quot...
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...
A class can have only one constructor, that is a method called initialize. The method is automatically invoked when a new instance of the class is created. class Customer def initialize(name) @name = name.capitalize end end sarah = Customer.new('sarah') sarah.name #=> 'Sarah' ...
In Python 2.6 and higher, math.copysign(x, y) returns x with the sign of y. The returned value is always a float. Python 2.x2.6 math.copysign(-2, 3) # 2.0 math.copysign(3, -3) # -3.0 math.copysign(4, 14.2) # 4.0 math.copysign(1, -0.0) # -1.0, on a platform which supports signed zero ...
The preferred method of file i/o is to use the with keyword. This will ensure the file handle is closed once the reading or writing has been completed. with open('myfile.txt') as in_file: content = in_file.read() print(content) or, to handle closing the file manually, you can forgo with...
In the event that geolocation fails, your callback function will receive a PositionError object. The object will include an attribute named code that will have a value of 1, 2, or 3. Each of these numbers signifies a different kind of error; the getErrorCode() function below takes the PositionError....
with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file: for line in in_file: out_file.write(line) Using the shutil module: import shutil shutil.copyfile(src, dst)
The following variables set up the below example: var COOKIE_NAME = "Example Cookie"; /* The cookie's name. */ var COOKIE_VALUE = "Hello, world!"; /* The cookie's value. */ var COOKIE_PATH = "/foo/bar"; /* The cookie's path. */ var COOKIE_EXPIRES; ...
var name = name + "=", cookie_array = document.cookie.split(';'), cookie_value; for(var i=0;i<cookie_array.length;i++) { var cookie=cookie_array[i]; while(cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length); if(cookie.indexOf(name)==0) ...
var expiry = new Date(); expiry.setTime(expiry.getTime() - 3600); document.cookie = name + "=; expires=" + expiry.toGMTString() + "; path=/" This will remove the cookie with a given name.
Since PHP 5.0, PDO has been available as a database access layer. It is database agnostic, and so the following connection example code should work for any of its supported databases simply by changing the DSN. // First, create the database handle //Using MySQL (connection via local socket): $d...
The basic syntax of SELECT with WHERE clause is: SELECT column1, column2, columnN FROM table_name WHERE [condition] The [condition] can be any SQL expression, specified using comparison or logical operators like >, <, =, <>, >=, <=, LIKE, NOT, IN, BETWEEN etc. The following ...
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...
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 ...
The background-color property sets the background color of an element using a color value or through keywords, such as transparent, inherit or initial. transparent, specifies that the background color should be transparent. This is default. inherit, inherits this property from its parent e...
One method is available for counting the number of occurrences of a sub-string in another string, str.count. str.count(sub[, start[, end]]) str.count returns an int indicating the number of non-overlapping occurrences of the sub-string sub in another string. The optional arguments start and end ...
Signed integers can be of these types (the int after short, or long is optional): signed char c = 127; /* required to be 1 byte, see remarks for further information. */ signed short int si = 32767; /* required to be at least 16 bits. */ signed int i = 32767; /* required to be at least 16 bits */ ...

Page 6 of 248