This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getconf LONG_BIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| busctl --user call org.gnome.Shell /org/gnome/Shell org.gnome.Shell Eval s 'Meta.restart("Restarting…")' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sw_vers -productVersion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| netstat -an -ptcp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try: | |
| f = open("demofile.txt") | |
| f.write("Lorum Ipsum") | |
| except: | |
| print("Something went wrong when writing to the file") | |
| finally: | |
| f.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Unpack tuples | |
| >>> fruits = ['lemon', 'pear', 'watermelon', 'tomato'] | |
| >>> first, second, *remaining = fruits | |
| >>> remaining | |
| ['watermelon', 'tomato'] | |
| >>> first, *remaining = fruits | |
| >>> remaining | |
| ['pear', 'watermelon', 'tomato'] | |
| >>> first, *middle, last = fruits | |
| >>> middle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tag(tag_name, **attributes): | |
| attribute_list = [ | |
| f'{name}="{value}"' | |
| for name, value in attributes.items() | |
| ] | |
| return f"<{tag_name} {' '.join(attribute_list)}>" | |
| >>> tag('a', href="http://treyhunner.com") | |
| '<a href="http://treyhunner.com">' | |
| >>> tag('img', height=20, width=40, src="face.jpg") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import randint | |
| def roll(*dice): | |
| return sum(randint(1, die) for die in dice) | |
| >>> roll(20) | |
| 18 | |
| >>> roll(6, 6) | |
| 9 | |
| >>> roll(6, 6, 6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> fruits = ['lemon', 'pear', 'watermelon', 'tomato'] | |
| >>> print(fruits[0], fruits[1], fruits[2], fruits[3]) | |
| lemon pear watermelon tomato | |
| >>> print(*fruits) | |
| lemon pear watermelon tomato | |
| >>> date_info = {'year': "2020", 'month': "01", 'day': "01"} | |
| >>> filename = "{year}-{month}-{day}.txt".format(**date_info) | |
| >>> filename | |
| '2020-01-01.txt' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fahrenheit = {'t1':-30, 't2':-20, 't3':-10, 't4':0} | |
| #Get the corresponding `celsius` values | |
| celsius = list(map(lambda x: (float(5)/9)*(x-32), fahrenheit.values())) | |
| #Create the `celsius` dictionary | |
| celsius_dict = dict(zip(fahrenheit.keys(), celsius)) |