Learning Python: Week 1 — From Operators to Generators

Quick Note

Where I Started

What I Learned

Indentation

if (x > 1) {
console.log("x is not 0");
}
if x > 1:
print("x is not 0")

Simultaneous Assignment

a,b = 1,2

Operators

a = 2 ** 3 //8
a = "hello" * 3 //hellohellohello
a = [1,2,3] * 3 // [1,2,3,1,2,3,1,2,3]

String Formatting

print("I am %d years old" % age)

Slicing Strings

x = "My name is Shahed"
print(x[3:10]) //name is

Boolean Operators

if x == 2 and y == 3:
print("x is 2 and y is 3")

Else in Loops

for i in range(1,5):
print("i is less than 5")
else:
print("i is greater than 5")

init Function in Classes

Modules

import user
user.create()
from user import create
from user import *
create()
import user as my_user

Packages

import blog.user
from blog import user
__all__ = ["user"]

Numpy Arrays

np_array = np.array([1,2,3])

np_array = np_array * 2 //[2,4,6]
np_array = np.array([1,2,3])

np_array[np_array > 1] //[2,3]

Pandas DataFrame

dataframe["name"]
dataframe[["name"]]
dataframe[["name", "age"]]

Generators

def age():
for i in range(5):
yield "I am %d years old" % i

for str in age():
print(str)
I am 0 years old
I am 1 years old
I am 2 years old
I am 3 years old
I am 4 years old

Where Next?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store