# python code to print pyramid pattern in python
def pyramid(n):
k = n - 1
for i in range(0, n):
for j in range(0, k):
print(end=" ")
k = k - 1
for j in range(0, i+1):
print("* ", end="")
print("\r")
n = 5
pyramid(n)
Output
*
* *
* * *
* * * *
* * * * *
Month: August 2021
How to check whether a file exists or not without exceptions in python ?
It is easy to check whether a file exists or not without exceptions in python ,python has a familiar os.path module using this module you can run isfile ,if it return True means a file exists or if it is False means file not exists
Code to check whether a file exists or not without exceptions in python
import os.path os.path.isfile(FILE_PATH) e.g >>> os.path.isfile("/home/index.html") True >>> os.path.isfile("/home/index_new.html") False
How to print the current date and time in Python
Here is the code to print the current date and time in Python
from datetime import datetime print datetime.now().strftime('%Y-%m-%d %H:%M:%S')
In python how to Find the index of an item in a list
Here we are going to elaborate In python how to Find the index of an item in a list,Suppose i have a list [“Red”, “blue”, “green”, “orange”] , How to find out in the color list what is the position or key of “green”
array1 = ["Red", "blue", "green", "orange"] print array1.index("green") Output 2