Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
Its high-level built in data structures, combined with dynamic typing and dynamic binding,
make it very attractive for Rapid Application Development, as well as for use as a scripting
or glue language to connect existing components together.
Python's simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance. Python supports modules and
packages, which encourages program modularity and code reuse. The Python interpreter
and the extensive standard library are available in source or binary form without charge
for all major platforms, and can be freely distributed.
Check each folder in the order of listing
Inside each folder will contain its own resources
Function:
def my_function():
print("Hello from a function")
Constructor:
class MotorBike:
def __init__(self, speed):
self.speed = speed
Abstract Class:
from abc import ABC, abstractmethod
class AbstractAnimal(ABC):
@abstractmethod
def bark(self): pass
Exception Handling:
Python exception handling:
try:
<block of statements>
except:
<block of statements>
else:
<block of statements>
finally:
<block of statements>
List Data Structure:
marks = [23, 56, 67]
Set Data Structure:
# Does not allow duplicates (its ignored) and does not maintain order.
marks = {23, 56, 67}
Dictionary:
occurances = dict(a=5, b=6, c=8)
Tuples:
# Immutable sequence of values
person = ('Alice', 30, 'USA')
List Comprehension:
numbers = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine']
numbers_length_four = []
numbers_length_four = [number for number in numbers if len(number) == 4]
print(numbers_length_four) # ['Zero', 'Four', 'Five', 'Nine']
Series:
# This will return Series with autogenerated index
adjectives = pd.Series(["Smart", "Handsome", "Charming", "Brilliant", "Humble", "Smart"])
print(adjectives)
# This will create Series with our own index and data
fruits = ["Apple", "Orange", "Plum", "Grape", "Blueberry", "Watermelon"]
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Monday"]
print(pd.Series(index=weekdays, data=fruits))
# Create Series with Dictionary
attack_powers = dict(Grass= 10,Fire= 15,Water= 15,Fairy_Fighting= 20,Grass_Psychic= 50)
print(pd.Series(attack_powers))
# 0r the below way
attack_powers = {
"Grass": 10,
"Fire": 15,
"Water": 15,
"Fairy, Fighting": 20,
"Grass, Psychic": 50
}
print(pd.Series(attack_powers))
# or the below way
attack_powers = pd.Series({
"Grass": 10,
"Fire": 15,
"Water": 15,
"Fairy, Fighting": 20,
"Grass, Psychic": 50
})
print(attack_powers)
# Import from CSV
# Squeeze converts DataFrame to Series
google = pd.read_csv("google_stock_price.csv", usecols=["Price"]).squeeze("columns")
# Import csv file with index column from 'Name'
pokemon = pd.read_csv("pokemon.csv", index_col="Name").squeeze("columns")
# Extract value by Index Location
print(pokemon.iloc[700:1010])
# Two ways of extracting value by Index Label
print(pokemon.loc["Meowth"])
print(pokemon.get("Meowth"))
# Extract multiple values by Index Label
print(pokemon.loc[["Charizard", "Jolteon", "Meowth"]])
# Extract value by Index Label with fall back value if not present
print(pokemon.get("Digimon", "Nonexistent"))
https://www.python.org/doc/essays/blurb/