Notes from multiple learning sources. Thank you all.
- 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
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"
Calling a function from anoher file
from hello_chai import chai
chai("ginger tea")
# this is comment
-
import myModule
-
dir(myModule)
-
you can also use as
from myModule import aGivenFunction
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.)
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
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")
- 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.
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}
- Addition: a + b
- Subtraction: a - b
- Multiplication: a * b
- Division: a / b
- Modulus: a % b
- Exponent: a ** b
- Floor Division: a // b
- 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
- Assigns value from right to left: a = b
- a += b ( a = a + b )
- a -= b
- a *= b
- a /= b
- a ** = b
- a //= b
- a and b
- a or b
- not a
- 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
- is: Evaluates to TRUE, if the variables on either side of the operator points to the same objects and FALSE otherwise.
- is not: