Skip to content

Amitmund/python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Notes

Notes from multiple learning sources. Thank you all.

Ref links:

Few of the best python book:

  • Python Crash Course ref youtube link
  • Python Programming By John Zelle
  • Algorithms Illuminated - Path1: The Basics - By Tim Roughgarden (Not in python, but fir Algo.
  • Python Tools for Scientiest.
  • Effective Panda

Chapter1

hello_chai.py

Creating a function, that can be used from a different file.
print("chai aur python")

def chai(n):
  print(n)

chai("lemon tea")

chai_one = "lemon tea"
chai_two = "ginger tea"
chai_three = "masala chai"

chai.py

Calling a function from anoher file
from hello_chai import chai

chai("ginger tea")

# this is comment

Knowing what are the functions, variables with in a module

  • import myModule

  • dir(myModule)

  • you can also use as from myModule import aGivenFunction

Note: 001

print("Hello"+"Python") # output: HelloPython (No space when we use +)
print("Hello", "Python") #Output: Hello Python (When we use , it add a space in between these two string.)

Note: 002

print("My age is" , 36) # This will work. As we are not doing any concanitation. ( So, good to use , ) 

print("My age is " + 36)  # This will give you error: "TypeError: must be str, not int"  # + expect both to be string.
Using + works for combining two strings — it concatenates them. It also works for two numbers — it adds the numbers together.

But, it can't join a string and a number.
  • This both will work. In comma, we don't need to add space.
  • In the second one we are using +, but giveing a space at the end of is, and using "27" as string.
print("My age is" , 27)
print("My age is " + "27")
print("Our combined age is 27" + "32") # output: Our combined age is 2732

Python Concatenation example!

Note: 003

seconds = 14926

hours = seconds//3600

minutes = (seconds - hours * 3600)//60

final_seconds = seconds%60

print(str(seconds) , "seconds is the same as")
print(str(hours) , "hours," , minutes  , "minutes, and" , final_seconds , "seconds")

seconds = 14926

hours = seconds // 3600

leftover_seconds = seconds % 3600

minutes = leftover_seconds // 60

final_seconds = leftover_seconds % 60

print(str(seconds) , "seconds is the same as")
print(str(hours) , "hours," , minutes  , "minutes, and" , final_seconds , "seconds")

Note: 004

Naming convention

  • Class names start with an Uppercase
  • Other identifiers start with lowercase
  • starting with single _ : private identifier
  • starting with double __ : strongly private
  • start and end with double __ : language defined special name.

Note: 005 : set

Example of set: set_a = {1,2,3} print(set_a) # output: {1,2,3}

set_b = {1,2,2,4} print(set_b) # output: {1,2,4}

Note: 006 : Arithmetic Operators

  • Addition: a + b
  • Subtraction: a - b
  • Multiplication: a * b
  • Division: a / b
  • Modulus: a % b
  • Exponent: a ** b
  • Floor Division: a // b

Note: 007: Assignment Operators

Python Assignment example!

Note: 008 : Comparison Operators

  • Equal to: a == b
  • Not Equal to: a != b
  • Greater than: a > b
  • Less than: a < b
  • Greater than equal to: a >= b
  • Less Than Equal to: a <= b

Note: 009 : Assignment Operators

  • Assigns value from right to left: a = b
  • a += b ( a = a + b )
  • a -= b
  • a *= b
  • a /= b
  • a ** = b
  • a //= b

Note: 010: Logical Operators:

  • a and b
  • a or b
  • not a

Note: 011: Bitwise Operators:

  • Binary AND: a & b
  • Binary OR: a | b
  • Bianry XOR: a ^ b
  • Binary NOT: a ~ b
  • Binary left shift: a <<
  • Binary Right Shift: a >> b

Identity Operators:

  • is: Evaluates to TRUE, if the variables on either side of the operator points to the same objects and FALSE otherwise.
  • is not:

Identity Operators

Note: 012: Membershif Operators:

Membershif Operators

About

python codes, notes, examples

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages