pycache:
pycache is a directory created by Python to store compiled versions of your Python scripts. These files have a .pyc extension and are generated automatically when a Python script is executed.
*Programming Rules: *
1) Known to Unknown
2) Don't think about entire output
3) Think ONLY about very next step
4) Introduce variable if necessary
5) Observe program closely
Write a program to print 5 consecutive number.
count = 1
if count<=5:
print(1, end=' ')
count=count+1 #count = 2
if count<=5:
print(1, end=' ')
count=count+1 # count = 3
if count<=5:
print(1, end=' ')
count=count+1 # count = 4
if count<=5:
print(1, end=' ')
count=count+1 # count = 5
if count<=5:
print(1, end=' ')
count=count+1 # count = 6
if statements, each printing the value 1 followed by a space (end=' ') if count <= 5. After each if block, count is incremented by 1.
1 1 1 1 1
Alternate implementation:
count = 1
while count <= 5:
print(1, end=' ')
count += 1
If the goal is to repeat this logic in a more concise way, a loop can be used
1 1 1 1 1
Short form of multiple if is called while.
The print() function uses two optional parameters, sep and end, to control the formatting of its output.
sep(Separator):
Specifies the string inserted between multiple arguments passed to print().
print("Hello", "World", sep=", ")
Hello, World
print("Kuhan",'guru','varatha',sep='-')
Kuhan-guru-varatha
end(End Character):
Specifies the string appended at the end of the output
print("Hello", end="!")
print("World")
Hello!World
Combining sep and end:
print("Python", "is", "fun", sep="-", end="!")
Python-is-fun!
Types of argument:
Positional argument:
Arguments passed in the exact order as specified in the function definition.
def add(no1,no2):
print(no1+no2)
add(10,20)
This calls the function add, passing 10 as no1 and 20 as no2.
30
Variable-Length Arguments:
Allow passing a variable number of arguments.
How to get only date from datetime module python:
from datetime import date
current_date=(date.today())
print("Current Date:",current_date)
Current Date: 2024-11-25
Top comments (0)