DEV Community

Kuhanraja A R
Kuhanraja A R

Posted on

day - 9 at payilagam python looping

Programming rules:
i) Known to unknown
ii) Don't think about the entire output
iii) Think only about the very next step
iv) Introduce variable if neccessary
v) Observe program closely

PYCACHE:

The pycache folder is a directory created by Python that stores compiled bytecode files (.pyc) of your Python scripts. This helps speed up the execution of your programs by allowing Python to use the pre-compiled bytecode instead of reinterpreting the source code each time.

program for 5 consecutive numbers:


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
Enter fullscreen mode Exit fullscreen mode

output:

1 1 1 1 1

Enter fullscreen mode Exit fullscreen mode
count = 1
while count <= 5:
    print(1, end=' ')
    count += 1
Enter fullscreen mode Exit fullscreen mode
output:
1 1 1 1 1
Enter fullscreen mode Exit fullscreen mode

The difference between two programs are same but when we can easily print upto five but when it comes to 100. it takes more time so, by easily introducing the variable into loop. we can easily write the program.
mainly it reduces time, for this while operator is used.

print("Hello", "World", sep=" , ")

Hello , World

print("ragu",'raju','ravi',sep='-')

ragu-raju-ravi

Enter fullscreen mode Exit fullscreen mode
print("Hello", end="$")
print("World")

Hello!World

Enter fullscreen mode Exit fullscreen mode

The difference between sep and end is sep adds the symbol in between the string and the end adds the symbol which is given by the user at the last.

def add(no1,no2):
    print(no1+no2)
add(10,20)


30
Enter fullscreen mode Exit fullscreen mode

arguments which are passed defines the function is called positional argument.
It is a positional argument.

variable - length arguments.
Allow passing a variable number of arguments.

n Python, *args is used to pass a variable number of arguments to a function. It is used to pass a variable-length, non-keyworded argument list. These arguments are collected into a tuple within the function and allow us to work with them.


from datetime import date
current_date=(date.today())

print("Current Date:",current_date)

Current Date: 2024-11-25
Enter fullscreen mode Exit fullscreen mode

import only date using python

Top comments (0)