# Print Simple Text to the Console
print("Hello World")
# Store Value in a Varibale
a = 5
print(a)
# Create Functions
def add_numbers(a, b):
"""
To add a discription, enter three "
Adds 2 numbers together
Returns
-------
the_sum : type of arguments
"""
return a + b
num = add_numbers(5, 10)
num
# Import a Package
import numpy as np
# Generate Random Data
data= [np.random.standard_normal() for i in range(7)]
np.random.standard_normal()
data
data[2:5]
Python Objects
Numbers
# Integer
a = 100
print(a)
type(a)
# Float
b = 100.7
b
# Complex
c = 100 + 200j
c
d = 300 + 500j
d
e = c + d
e
type(e)
List
A list is an ordered collection of mutable items which can be of any type. Show elements of a list using brackets [ ].
a = [4, 6, 3, 2, 5]
a
a[3]
b = ['Physics', 'Chemistry', 91, 100.7]
b
b[-1]
91 in b
b.index(91)
Tuple
A tuple is an ordered collection of immutable items which can be of any type. Tuples are represented by parentheses ( )
a= (1, 2, 3, 4, 5)
a
b = (3, 5, 6)
b
a + b
a*2
# a = a*3
a*= 3
print(a)
Dictionary
A dictionary is a list of keys. Each key is associated with a value. Each key is separated from its value by a colon : , the items are separated by commas, and the whole thing is enclosed n curly braces { }
List [Brackets]
Tuple (Parentheses)
Dictionary {Braes}
capitals = {'France': 'Paris', 'Germany': 'Berlin', 'Italy': 'Rome'}
capitals
capitals2 = {'United Kingdom': 'London', 'United States': 'Washington'}
capitals2