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
# 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 |
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
# 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 |
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
#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 |