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
# a function decorator to avoid digital screaming | |
def lowercase(func): | |
def wrapper(text): | |
initial_result = func(text) | |
new_result = initial_result.lower() | |
return new_result | |
return wrapper | |
@lowercase | |
def say_something(text): |
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
name = "Mycroft" | |
def print_name_box(): | |
print(name) | |
def smaller_box(): | |
''' | |
(re)assigning a variable within the same scope | |
overwrites the same variable from an outer scope | |
-> you cannot use it *before* assigning it, |
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
name = "Mycroft" | |
def print_name_box(): | |
print(name) | |
def smaller_box(): | |
print(name) | |
def smallest_box(): | |
print(name) |
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
name = 'codingnomads' | |
# trying to change the string directly causes an error | |
# name[8:] = 'rmals' | |
# TypeError: 'str' object does not support item assignment | |
# we need to create a new string | |
new_name = name[:8] + 'rmals' # using string slicing and concatenation | |
print(name, new_name) | |
# after re-assigning the value, the old 'name' is overwritten |
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
# creating a python string with single quotes | |
job = 'coding' | |
# creating a python string with double quotes | |
location = "nomad" | |
print(job, location) # both of them work fine | |
# however, a mix-up of the two does not work and produces a SyntaxError |
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
# simple float calculation | |
print(42.42 / 3) | |
# mixing integers with floats yields floats | |
part_of_whole = 0.5 | |
whole = part_of_whole * 2 | |
print(whole) |
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
# simple addition using variables and integers | |
pre_course_weeks = 2 | |
onsite_weeks = 6 | |
online_weeks = 4 | |
course_duration = pre_course_weeks + onsite_weeks + online_weeks | |
print(course_duration) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8'> | |
<title>d3eath sentence</title> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<style type='text/css'> | |
/*some style for the visualization*/ |
NewerOlder