Function Use: To print all the directories in a folder/sub-folder or directory import os def get_list_or_dir(local_dir): for dir_or_file in os.listdir(local_dir): if os.path.isdir(dir_or_file): path = os.path.join(local_dir, dir_or_file) print(dir_or_file, 'This is a directory') get_list_or_dir(path) else: print(dir_or_file) Path = os.getcwd() or define the path from where you need a file Function Call: get_list_or_dir(path)
Welcome to the second post about printing the patterns in Python. Today we will learn about printing the below patterns in Python.
1>
*
* *
* * *
* * * *
2>
* * * *
* * *
* *
*
We will recommend you to read the Printing pattern in Python Ep1 first, as it will help you understand better.
1> Program to print first pattern.
>>> n = 4
>>> for i in range(1, n+1):
print(i*"* ")
*
* *
* * *
* * * *
2> Program to print second pattern.
>>> n = 4
>>> for i in range(0, n):
print((n-i)*"* ")
* * * *
* * *
* *
*
Keep reading Python an hour a day to learn simple Python tricks, tips and program.
1>
*
* *
* * *
* * * *
2>
* * * *
* * *
* *
*
We will recommend you to read the Printing pattern in Python Ep1 first, as it will help you understand better.
1> Program to print first pattern.
>>> n = 4
>>> for i in range(1, n+1):
print(i*"* ")
*
* *
* * *
* * * *
2> Program to print second pattern.
>>> n = 4
>>> for i in range(0, n):
print((n-i)*"* ")
* * * *
* * *
* *
*
Keep reading Python an hour a day to learn simple Python tricks, tips and program.
Comments
Post a Comment