› Kinyanjui Wangonya

Software engineer - previously at Andela, now at Jenga.

If you’re new to celery, start here.

Sometimes when using celery, you may want to get notified when a task running in the background executes successfully or when it fails. You may also want to run a function each time before the celery task runs or after it completes. These and many others along the same line are all situations where signals would come in handy.

What happens when a variable is assigned to another variable in python? For example:

>>> x = 5
>>> y = x

Both x and y will have the value 5. But, when x was assigned to y, y was not created as a completely new/separate object. Instead, an alias for x was created. That is, y points to the memory location of x. It does not have it’s own memory location - yet.

>>> id(x)
140428600776960
>>> id(y)
140428600776960
>>> x is y
True

By default, variables are immutable in Rust. Coming from a Python background, I have to keep in mind that this:

fn main() {
    let var = 10;
    println!("var = {}", var);  // var = 10
    var = 5;  // try and reassign var
    println!("var is now {}", var);
}

… will not compile.

The range() function is often useful when iterating over a set of integers:

for n in range(50):
    ...

#

for n in range(10, 30):
    ...

or a list of strings:

for fruit in ["apple", "mango", "banana"]:
    ...

Say we have a list of strings: _list = [...,] and user input _input = '...', how do we find the items in _list that most closely resemble _input?

Python has a built-in package called difflib with the function get_close_matches() that can help us.

Note: * represents a required parameter.

join()

Parameters

string.join(iterable)

iterable*: a python iterable e.g a list, tuple, string, dictionary or set.

Return value

Returns a string concatenated with the elements of the passed in iterable.

capitalize()

Parameters

string.capitalize()

capitalize() takes no parameters.

Return value

Returns a copy of the string with the first letter of the first word capitalized and all the other characters of the string in lowercase.

I just came across this online HTML to JSX Compiler. If you’re new (or not) to react and you’re still having a little trouble with JSX, I think this tool is great for learning.

Note: * represents a required parameter.

find()

Parameters

string.find(substring, start, end)

substring*: the substring to be searched in the string.

start: index from which to begin the search.

end: index at which to end the search.

Return value

Returns an integer value pointing to the index of first occurrence of the substring. If the substring is not found, it returns -1.

A lot of times when I’m doing ifs in Python, I find myself wondering whether to use is or == for the check.

# do I do
if a is b:
    ...

# or
if a == b:
    ...

It can be a bit confusing if you’re new to Python, and it’s easy to assume the two can be used interchangeably. So, what’s the difference?

« Older posts Newer posts »