Found 10784 Articles for Python

Python program to change the value of a dictionary if it equals K

Niharika Aitam
Updated on 19-Oct-2023 14:38:42

39 Views

Dictionary is one of the data structure available in python to store any datatype of data in the format of key and value pair. It is denoted by {} curly braces. The key in the dictionary is unique and the values in the dictionary can be repeated. The key and values pairs are separated by using the semi colon ‘:’. It is mutable i.e. once the dictionary created, we can modify the data. Dictionaries are versatile and widely used in Python for mapping and storing data where quick access to values based on keys is required. The dictionary is unordered ... Read More

Python program to calculate gross pay

Niharika Aitam
Updated on 19-Oct-2023 14:36:00

176 Views

Basically Gross pay is the total amount paid to an employee for the total time he/she worked, i.e. this is the full amount of salary of an employee before the taxes and deductions. The Gross pay also includes the bonuses, overtime or reimbursements from an employer on top of the salary pay. Mathematically the formula for the gross pay is as follows. Hours worked * pay per hour = gross pay per period For example, if an employee worked for 200 hours in a given period and earned Rs.300/- for an hour then the gross pay will be ... Read More

Python program to calculate square of a given number

Niharika Aitam
Updated on 19-Oct-2023 14:27:05

419 Views

Square is the defined as the multiplication of the number by itself. The square of a number n is given as n2. Mathematically we can implement square of the number as follows. $\mathrm{n^{2}=n*n}$ In the same way we can calculate the square of a given number by using python language too. There are few approaches in python to find the square of a number, let’s see them one by one. Using exponential operator (**) The exponential operator is the operator which is used to perform the exponent arithmetic operation. It is denoted with the symbol **. Syntax The ... Read More

Python program to calculate Date, Month and Year from Seconds

Niharika Aitam
Updated on 19-Oct-2023 14:23:07

287 Views

Generally, time is given in hours or minutes or seconds and from the given seconds, we can calculate the number of days, months and years. There are different modules and functions available in python such as datetime, time and divmod() which helps us to calculate the date month and year from seconds. Using Datatime module Datetime module offers classes to manipulate the dates and times. This module provides various functions and methods such as date, time, datetime, timedelta, minyear, maxyear, UTC etc. In the datetime method of datetime module we have the function utcfromtimestamp() which takes the seconds as ... Read More

Python program to calculate age in year

Niharika Aitam
Updated on 19-Oct-2023 14:20:56

6K+ Views

Generally, the age of a person is calculated by subtracting the birth year with the current year then the age of the person will be generated in years. In the same way we can calculate the age of a person by using the python modules datetime, dateutil and timedelta. General Calculation of Age in years Current year - Birth year Example In this example we are implementing the general way of calculating the age using pythn language by passing the current year and birth years as the inputs to created function age_calculator() then the total age will be generated ... Read More

Python program to calculate acceleration, final velocity, initial velocity and time

Niharika Aitam
Updated on 19-Oct-2023 14:17:19

631 Views

Acceleration, final velocity, initial velocity and time are the terms related to physical science which are widely used to study the motion and mechanics. Let’s see each one in detail. Acceleration Acceleration is the rate at which an object changes its velocity over the given time. It is denoted by a. Mathematically it is defined as the change in velocity divided by the change in time, the following is the formula. The unit of acceleration is meters per second $\mathrm{(m/s^2)}$ $\mathrm{a \:=\:(\Delta;\:vf − \Delta;vi)/\Delta;t}$ Where, $\mathrm{\Delta\:vi}$ is the Initial velocity $\mathrm{\Delta\:vf}$ is the Final velocity $\mathrm{\Delta\:t}$ is the ... Read More

Profiling in Python

Niharika Aitam
Updated on 19-Oct-2023 14:14:53

65 Views

In Python profiling is the measure of performance of different parts of a program to check and identify the areas of optimization and bottlenecks. We have many tools to perform profiling for the python code which includes built in modules, libraries and IDEs (Integrated development environments). There are different types of profiling of the python code, let’s see them one by one. Using Line profiling Line profiling is the technique used to measure the execution time of each individual line of the program. It helps us to identify which line is taking more execution time and to identify the tight ... Read More

Profile Application using Python Flask and MySQL

Niharika Aitam
Updated on 19-Oct-2023 14:12:47

133 Views

Flask is one of the web frameworks which provide libraries to build light weight web applications in python. It is a micro framework, developed by Armin Ronacher who runs an international group of python enthusiasts (POCCO). Flask works on WSGI toolkit and jinja2 template engines. For creating the profile application using python flask and MySQL we have to follow the below mentioned steps one by one. Step − 1 Install the virtual environment by executing the below mentioned command in the command prompt. pip install virtualenv Once the virtual environment is created we can create the new virtual environment into ... Read More

ProcessPoolExecutor Class in Python

Niharika Aitam
Updated on 19-Oct-2023 14:07:03

72 Views

The ProcessPoolExecutor class in python is part of the concurrent.futures module, is a high level interface for asynchronously executing functions using the processes and threads. The ProcessPoolExecutor allows us to execute the multiple functions in parallel using the multiple processes, which is particularly useful to CPU bound tasks that benefit in the parallelization process. Multiprocessing and Multithreading Before going to see about the ProcessPoolExecutor class we have to know about the Multiprocessing and Multithreading. Multiprocessing and Multithreading are the techniques used to achieve the parallelism process and they are different in the way they manage and create concurrent tasks. Multiprocessing ... Read More

Private Methods in Python

Niharika Aitam
Updated on 19-Oct-2023 14:04:56

897 Views

In Python, we can define the private method by prefixing the single underscore to the method name and like the other programming languages we cannot prevent accessing the private method outside the class in python. Simply we can say the private method is used only internally for the defined class. What is private method and public method? A private method is the method that should be called only inside the defined class whereas the Public method is defined within the class, can be called on an instance of the defined class. Now let’s define the private method and see ... Read More

Advertisements