Posts

Showing posts from June, 2018

Python Loop & range() Function

Image
  Concept The function  range()  can take 1 to 3 of the following arguments. i)   Start ii)  End iii) Step range(start, stop, step) Note: The Default value of start is Zero always. End value user need to be mention The Default value for step is 1 always Code Example ------------------------------------------------------- For Loop ----------------------------------------------------- Example 1: for i in range(1, 6, 1):     print(i) Output:  1 2 3 4 5   Example 2: for i in range(1, 51, 10):     print(i) Output:  1 11 21 31 41   Example 3: for i in range(6):     print(i) Output:  0 1 2 3 4 5   Example 4: for i in range(50, 0, -10):     print(i) Output: 50 40 30 20 10 ------------------------------------------------------- While Loop ----------------------------------------------------- Example 1: >>> while count < limit: print(count) count += 1 OutPut: 1 2 3 4 5 6 7 8 9 # infinite loop with while Example 2: while True:       print("I will be printing  infinite times&q

IF-ELSE In Python

Image
Code Example 1: # Find the largest among 2 numbers x, y = 2, 1 if x>y:     print("Big is : ", x) else:     print("Big is : ", y) Example 2: print("--------------------------") # Find the largest among 3 numbers a, b, c = 6, 4, 7 if a>=b and a>=c:     print("A") elif b>=a and b>=c:     print("B")  elif c>=b and c>=a:     print("C") Example 3: print("--------------------------") a, b, c = 8, 4, 7 if a>b:     if a>c:         print("a is max")     else:         print("c is max") elif b>a:     if b>c:         print("b is max")     else:         print("c is max") else:     print("c is max")  Example 4: x, y = 10, 20 print(x) if x>y else print(y) Screenshot : Enjoy Edge-cutting Technology 😉 Quiz Level 1 Quiz Level 2 Request Me

Datetime In Python

Image
  Code Example Example 1: >>> import datetime >>> today = datetime.datetime.now() >>> print(today) 2020-09-06 16:39:12.862160 >>>print(today.year,'-', today.month,  '-',  today.day) 2020 - 9 - 6 Example 2: >>> import datetime >>> old_date = datetime.date(2020, 10, 20) >>> print(old_date) 2020-10-20 Example 3: >>> from datetime import datetime, timedelta >>> today = datetime.now() >>> print(today) 2020-09-06 16:45:32.176510 >>> date_after_30_days = today + timedelta(days=30) >>> print(date_after_30_days) 2020-10-06 16:45:32.176510 >>> date_before_60_days = today - timedelta(days=60) >>> print(date_before_60_days) 2020-07-08 16:45:32.176510 Example 4: # Local Datetime >>> import datetime >>> import pytz >>> current_time = datetime.datetime.now(pytz.timezone('Asia/Kolkata')) >>> print(current_time) 2020-09