Posts

PYTHON DIRECTORIES AND FILES MANAGEMENT

Image
DIRECTORIES AND FILES MANAGEMENT # If there are a large number of files to handle in python, we can arrange our code within different directories to make things more manageable. # A directory is a collection of files and sub directories. # Python has the os module that provides many useful methods to work with directories and files. # get current directory. getcwd() # This module returns the current working directory in the form of a string. # We can also use: getcwdb() # method to get it as bytes object. import os os.getcwd() os.getcwdb() print (os.getcwd()) # Changing directory. chdir() # We can change the current working directory by using this method. # The new path that we want to change into must be supplied as a string to this method. # We can use both forward slash(/) and backward slash (\) to separate path elements. os.chdir( 'C: \\ Python3' ) print (os.getcwd()) # List of directories and files. # All files and sub directories inside a direc

Lambda Function (PYTHON)

# SYNTAX. # lambda arguments : expression # Addition using LAMBDA function. x = lambda a : a + 10 print (x( 5 )) #The expression is executed and output is returned. # Subtraction using Lambda function y= lambda b:b- 20 print (y( 30 )) # Multiplication using LAMBDA function. x = lambda a : a * 10 print (x( 4 )) # Division using LAMBDA function. x = lambda a : a / 10 print (x( 5 )) # More than one argument. x = lambda a , b , c : a + b + c print (x( 5 , 6 , 2 )) # Lambda function with another function. # Function that doubles the value. def myfunc (n):   return lambda a : a * n mydoubler = myfunc( 2 ) print (mydoubler( 11 )) #   Similarly we can change the values passed and get different results.     #python #programming #coding #programmer #snake #machinelearning #code #coder #ballpython #pythonprogramming #computerscience #datascience #reptile #snakes #reptiles #snakesofinstagram #reptilesofinstagram #technology #pythonsofinstagram #artificialintelli

MATRIX BASIC PROGRAMS (PYTHON)

  # MATRIX input. row = int ( input ( "Enter the number of rows:" )) column = int ( input ( "Enter the number of columns:" )) # Addition of two MATRICES. X=[[ 1 , 2 , 3 ] , [ 3 , 4 , 5 ] , [ 6 , 7 , 8 ]] Y=[[ 3 , 4 , 5 ] , [ 6 , 4 , 5 ] , [ 5 , 9 , 8 ]] Z=[[ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ]] for i in range ( len (X)): #len[X] is length of rows i.e no of small brackets. for j in range ( len (X[ 0 ])): #X[0] gives idea of number of columns. Z[i][j]=X[i][j]+Y[i][j] for r in Z: print (r) # Subtraction of two MATRICES. X=[[ 2 , 3 , 4 ] , [ 4 , 5 , 6 ] , [ 7 , 6 , 7 ]] Y=[[ 3 , 4 , 5 ] , [ 6 , 7 , 8 ] , [ 2 , 1 , 3 ]] Z=[[ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ]] for i in range ( len (X)): for j in range ( len (X[ 0 ])): Z[i][j] = X[i][j] - Y[i][j] for r in Z: print (r) # Multiplication of two MATRICES. X=[[ 1 , 2 , 3 ] , [ 3 , 4 , 5 ] , [ 6 , 7 , 8 ]] Y=[[ 3 , 4 , 5 ] , [ 6 , 4 , 5

PYTHON BASIC PROGRAMS

#1.Hello world program. print ( "Hello World" )   #2.Addition of two numbers. a= int ( input ( "Enter the   first number" )) b= int ( input ( "Enter the second number" )) print (a+b)   #3.To find the square root &$ check the program. a= float ( input ( "enter the number" ) # b= a ** 0.5 print (b)   #4.To find area of triangle. a= float ( input ( "enter the base of triangle" )) b= float ( input ( "enter the height of triangle" )) c=( 1 / 2 )*a*b print ( "The area of triangle is" , c) OR a= float ( input ( "enter the base side of triangle" )) b= float ( input ( "enter the 2nd side of triangle" )) c= float ( input ( "enter the 3rd side of triangle" )) d=(a+b+c)/ 2 area=(d*(d-a)*(d-b)*(d-c))** 0.5 print (area)   #5.Swapping 2 variables. a= int ( input ( "enter the number1" )) b=( int ( input ( "enter the second

Popular posts from this blog