Python

Python is a nice little language, it took me a while to get used to it's use of indentation to mark blocks no begin end or braces. Python is powerful and clean but not as expressive as Perl.

a python function looks like this:

def f(arg):

if arg == 'fred':

return 1

else:

return 2


I have just learned, python has '''string''' triple single quoted strings as well as the """string""" triple double quoted strings I've always know.

and python 3 has f-strings i.e.


>>> x = 10

>>> y = 42

>>> z = "hello world"

>>> print(f" x == {x}, y == {y}, x + y == {x + y}, z == {z}")

x == 10, y == 42, x + y == 52, z == hello world

>>> print(f"""x == {x}, y == {y}, x + y == {x + y}, z == {z}""")

x == 10, y == 42, x + y == 52, z == hello world

>>> print(f'x == {x}, y == {y}, x + y == {x + y}, z == {z}')

x == 10, y == 42, x + y == 52, z == hello world

>>> print(F"""

hello { f"hi {z} " } {x} {y}""")


hello hi hello world 10 42

>>> p = f'''

hello

how are you {z}

'''

>>> p

'\nhello\nhow are you hello world\n'

>>> print(p)


hello

how are you hello world


>>> f'{(lambda x: x*2)(3)}'

'6'

>>>

Note: lambdas in python are almost completely useless, as they can only have one expression and no statements

f-strings are my latest discovery:

who = 'world'

print(f" hello {who}")

would print: hello world

you can use lower or uppercase f and any string type i.e. f"""

{expr}

""""

you can put pretty much any expression in there. so much easier than str.format() or the ancient "%d %s" % (42, 'hello')