Tutorial by Examples: du

Instead of importing the complete module you can import only specified names: from random import randint # Syntax "from MODULENAME import NAME1[, NAME2[, ...]]" print(randint(1, 10)) # Out: 5 from random is needed, because the python interpreter has to know from which resource it...
from module_name import * for example: from math import * sqrt(2) # instead of math.sqrt(2) ceil(2.7) # instead of math.ceil(2.7) This will import all names defined in the math module into the global namespace, other than names that begin with an underscore (which indicates that the wri...
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...
Definition: In computing, an event is an action or occurrence recognized by software that may be handled by the software. Computer events can be generated or triggered by the system, by the user or in other ways. Definition Source HTML events are "things" that happen to HTML ele...
The differences between null and undefined null and undefined share abstract equality == but not strict equality ===, null == undefined // true null === undefined // false They represent slightly different things: undefined represents the absence of a value, such as before an identifier/...
The json module contains functions for both reading and writing to and from unicode strings, and reading and writing to and from files. These are differentiated by a trailing s in the function name. In these examples we use a StringIO object, but the same functions would apply for any file-like obje...
Generator expressions are similar to list, dictionary and set comprehensions, but are enclosed with parentheses. The parentheses do not have to be present when they are used as the sole argument for a function call. expression = (x**2 for x in range(10)) This example generates the 10 first perfe...
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...
You can include another Git repository as a folder within your project, tracked by Git: $ git submodule add https://github.com/jquery/jquery.git You should add and commit the new .gitmodules file; this tells Git what submodules should be cloned when git submodule update is run.
When you clone a repository that uses submodules, you'll need to initialize and update them. $ git clone --recursive https://github.com/username/repo.git This will clone the referenced submodules and place them in the appropriate folders (including submodules within submodules). This is equivale...
Magic (also called dunder as an abbreviation for double-underscore) methods in Python serve a similar purpose to operator overloading in other languages. They allow a class to define its behavior when it is used as an operand in unary or binary operator expressions. They also serve as implementation...
def multiply(s1, s2): print('{arg1} * {arg2} = {res}'.format(arg1=s1, arg2=s2, res=s1*s2)) return s1 * s2 asequence = [1, 2, 3] Given an initializer the function is started by applying it to the...
import operator reduce(operator.mul, [10, 5, -3]) # Out: -150
The math-module contains another math.pow() function. The difference to the builtin pow()-function or ** operator is that the result is always a float: import math math.pow(2, 2) # 4.0 math.pow(-2., 2) # 4.0 Which excludes computations with complex inputs: math.pow(2, 2+0j) TypeErro...
A submodule references a specific commit in another repository. To check out the exact state that is referenced for all submodules, run git submodule update --recursive Sometimes instead of using the state that is referenced you want to update to your local checkout to the latest state of that s...
A submodule is always checked out at a specific commit SHA1 (the "gitlink", special entry in the index of the parent repo) But one can request to update that submodule to the latest commit of a branch of the submodule remote repo. Rather than going in each submodule, doing a git checkout...
You can use the trap command to "trap" signals; this is the shell equivalent of the signal() or sigaction() call in C and most other programming languages to catch signals. One of the most common uses of trap is to clean up temporary files on both an expected and unexpected exit. Unfortu...
println! (and its sibling, print!) provides a convenient mechanism for producing and printing text that contains dynamic data, similar to the printf family of functions found in many other languages. Its first argument is a format string, which dictates how the other arguments should be printed as t...
PorterDuff.Mode is used to create a PorterDuffColorFilter. A color filter modifies the color of each pixel of a visual resource. ColorFilter filter = new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN); The above filter will tint the non-transparent pixels to blue color. The color fil...
An Xfermode (think "transfer" mode) works as a transfer step in drawing pipeline. When an Xfermode is applied to a Paint, the pixels drawn with the paint are combined with underlying pixels (already drawn) as per the mode: paint.setColor(Color.BLUE); paint.setXfermode(new PorterDuffXferm...

Page 2 of 47