Skip to content

Instantly share code, notes, and snippets.

View funkycoder's full-sized avatar

Quan Nguyen funkycoder

View GitHub Profile
@funkycoder
funkycoder / switch.py
Created December 11, 2020 08:05
Switch statement in python
# Python doesnt have switch case statement. Hereis the workaround
def grading(score):
switcher = {
0: "Zero",
1: "One",
2: "Two",
3: "Three",
4: "Four",
}
# get() method of dictionary data type returns
@funkycoder
funkycoder / for_loop.py
Created December 8, 2020 03:48
For loop in Python
# For loops in Python works like iterator in other language
# Execute a set of statements, once for each item in a list, tuple or set
# Print name in a list of names
names = ["John", "Henry", "Matt", "Rocky"]
for name in names:
print(name)
# >>>John
# >>>Henry
@funkycoder
funkycoder / NaN.py
Last active December 5, 2020 15:22
NaN and Inf in Python
#Q: How do you represent NaN of Inf in Python?
#A: Call float(x) with x as either the string "NaN" or "Inf" to create a NaN or Inf value.
nan = float('NaN')
inf = float('Inf')
#Q: How to check NaN of Inf value
#A: math.isnan(x), math.isinf(x)
import math
math.isnan(nan)
>>> True