Tutorial by Examples: ar

In Python, variables inside functions are considered local if and only if they appear in the left side of an assignment statement, or some other binding occurrence; otherwise such a binding is looked up in enclosing functions, up to the global scope. This is true even if the assignment statement is ...
A for loop iterates over a sequence, so altering this sequence inside the loop could lead to unexpected results (especially when adding or removing elements): alist = [0, 1, 2] for index, value in enumerate(alist): alist.pop(index) print(alist) # Out: [1] Note: list.pop() is being used t...
There are several special variable types that a class can use for more easily sharing data. Instance variables, preceded by @. They are useful if you want to use the same variable in different methods. class Person def initialize(name, age) my_age = age # local variable, will be destroyed ...
We have three methods: attr_reader: used to allow reading the variable outside the class. attr_writer: used to allow modifying the variable outside the class. attr_accessor: combines both methods. class Cat attr_reader :age # you can read the age but you can never change it attr_writer...
math.log(x) gives the natural (base e) logarithm of x. math.log(math.e) # 1.0 math.log(1) # 0.0 math.log(100) # 4.605170185988092 math.log can lose precision with numbers close to 1, due to the limitations of floating-point numbers. In order to accurately calculate logs close to 1, ...
There is a problem when using optional arguments with a mutable default type (described in Defining a function with optional arguments), which can potentially lead to unexpected behaviour. Explanation This problem arises because a function's default arguments are initialised once, at the point whe...
Array is an ordered collection type in the Swift standard library. It provides O(1) random access and dynamic reallocation. Array is a generic type, so the type of values it contains are known at compile time. As Array is a value type, its mutability is defined by whether it is annotated as a var (...
The following examples will use this array to demonstrate accessing values var exampleArray:[Int] = [1,2,3,4,5] //exampleArray = [1, 2, 3, 4, 5] To access a value at a known index use the following syntax: let exampleOne = exampleArray[2] //exampleOne = 3 Note: The value at index two is th...
There are multiple ways to append values onto an array var exampleArray = [1,2,3,4,5] exampleArray.append(6) //exampleArray = [1, 2, 3, 4, 5, 6] var sixOnwards = [7,8,9,10] exampleArray += sixOnwards //exampleArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and remove values from an array exampleAr...
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 ...
Download Xcode from the Mac App Store. Click to create a new project or playground:
Create a new HTML file and paste the following content: <!DOCTYPE html> <html ng-app> <head> <title>Hello, Angular</title> <script src="https://code.angularjs.org/1.5.8/angular.min.js"></script> </head> <body ng-init="name=...
Create a new file called hello.sh with the following content and give it executable permissions with chmod +x hello.sh. Execute/Run via: ./hello.sh #!/usr/bin/env bash # Note that spaces cannot be used around the `=` assignment operator whom_variable="World" # Use printf to sa...
Creating a database in MySQL CREATE DATABASE mydb; Return value: Query OK, 1 row affected (0.05 sec) Using the created database mydb USE mydb; Return value: Database Changed Creating a table in MySQL CREATE TABLE mytable ( id int unsigned NOT NULL auto_increme...
By default, the math.log function calculates the logarithm of a number, base e. You can optionally specify a base as the second argument. import math import cmath math.log(5) # = 1.6094379124341003 # optional base argument. Default is math.e math.log(5, math.e) # = 1.6094379124341003 ...
Direction-Specific Properties CSS allows you to specify a given side to apply margin to. The four properties provided for this purpose are: margin-left margin-right margin-top margin-bottom The following code would apply a margin of 30 pixels to the left side of the selected div. View Resu...
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 ...
Dictionaries are an unordered collection of keys and values. Values relate to unique keys and must be of the same type. When initializing a Dictionary the full syntax is as follows: var books : Dictionary<Int, String> = Dictionary<Int, String>() Although a more concise way of initia...
Add a key and value to a Dictionary var books = [Int: String]() //books = [:] books[5] = "Book 5" //books = [5: "Book 5"] books.updateValue("Book 6", forKey: 5) //[5: "Book 6"] updateValue returns the original value if one exists or nil. let previous...
The <article> element contains self-contained content like articles, blog posts, user comments or an interactive widget that could be distributed outside the context of the page, for example by RSS. When article elements are nested, the contents of the inner article node should be related t...

Page 7 of 218