Found 10784 Articles for Python

Lambda expression in Python Program to rearrange positive and negative numbers

Hafeezul Kareem
Updated on 24-Apr-2020 12:34:21

579 Views

In this tutorial, we are going to write an anonymous function using lambda to rearrange positive and negative number in a list. We need the pick the negative numbers and then positive numbers from a list to create a new one.AlgorithmLet's see how to solve the problem step by step.1. Initialize a list with negative and positive numbers. 2. Write a lambda expression the takes a list as an argument.    2.1. Iterate over the list and get negative numbers    2.2. Same for positive numbers    2.3. Combine both using concatination operator. 3. Return the resultant list.Note - Use ... Read More

Log functions in Python Program

Hafeezul Kareem
Updated on 24-Apr-2020 12:32:25

350 Views

In this tutorial, we are going to learn about the logarithmic functions from math module. We have four variants of logarithmic functions. Pythons' provides all of them in the math module. Let's learn about them one by one.math.log(number, [Base])The math.log(number, [Base]) method is used to compute the logarithm of any Base. If we didn't specify any base value, then it will take e as default base.Note − You will get ValueError if you pass a negative number to the method.ExampleLet's see some examples. Live Demo# importing math module import math # logarithm with base 3 print(math.log(15, 7))OutputIf you run the above ... Read More

Private Variables in Python Program

Hafeezul Kareem
Updated on 24-Apr-2020 12:30:05

3K+ Views

In this tutorial, we are going to learn about the private variables in Python classes.Python doesn't have the concept called private variables. But, most of the Python developers follow a naming convention to tell that a variable is not public and it's private.We have to start a variable name with a double underscore to represent it as a private variable (not really). Example:- one, two, etc.., .As we already said the variables whose names start with a double underscore are not private. We can still access. Let's see how to create private type variables and then we will see how ... Read More

Python Dictionary Comprehension

Hafeezul Kareem
Updated on 24-Apr-2020 12:26:13

242 Views

In this tutorial, we are going to learn how to use dictionary comprehensions in Python. If you are already familiar with list comprehension, then it won't take much time to learn dictionary comprehensions.We need the key: value pairs to create a dictionary. How to get these key-value pairs using dictionary comprehension? See the general statement of dictionary comprehension.{key: value for ___ in iterable}We need to fill in the above statement to complete a dictionary comprehension. There are many ways to fill it. Let's see some of the most common ways.Let's see how to generate numbers as keys and their squares ... Read More

Program to print its script name as output in Python

Hafeezul Kareem
Updated on 24-Apr-2020 12:20:22

928 Views

In this tutorial, we are going to write a program that prints the name of the Python script file. We can find the script name using the sys module.The sys module will store all the command line arguments of python command in the sys.argv list. The first element in the list is the script name. We can extract it from that list. Python makes it easy.Let's see the steps involved in the program.Import the sys module.Now, print the first element of the sys.argv list.That's it. You got the script name.ExampleLet's see it practically. Live Demo# importing the sys module import sys ... Read More

Difference between Python and Ruby

Kiran Kumar Panigrahi
Updated on 25-Aug-2022 13:09:18

239 Views

Python is a high-level, general-purpose programming language. It is used in website development, machine learning, and creative software technology. Guido Van Rossam created Python in the Netherlands in 1989. Python became public in 1991. New programmers are typically advised to learn Python. Ruby is an interpreted, open-source, object-oriented language. It was developed by Yukihiro Matsumoto in the year 1995. Ruby is an object-oriented language, hence everything is an object. OOP gives developer projects a modular structure. Read through this article to find out more about Python and Ruby and how they are different from each other. What is ... Read More

try and except in Python Program

Hafeezul Kareem
Updated on 24-Apr-2020 12:17:13

362 Views

In this tutorial, we are going to learn about the try and except of Python. Python has a concept called error and exception handling.The keywords try and except are used in the error and exception handling.Basically, we will find two types of errors in Python. They are −Syntax errors - Python gives these types of error when it doesn't understand a line of code in the program.Exception errors - Errors which are detected during the runtime of the program. Ex:- ZeroDivisionError, ValueError, etc.., We can't stop syntax errors. But, we can intimate if the program runs into an exception error ... Read More

Unit Testing using Unittest in Python

Hafeezul Kareem
Updated on 24-Apr-2020 12:12:21

591 Views

In this tutorial, we are going to learn about Unit Testing using the unittest built-in module. Testing plays a major role in software development. You will know the issues before going to the production itself.We'll learn the basics of testing in Python using the built-in module called unittest. Let's jump into the tutorial.What is Unit Testing?If you take the login system as an example. Each field in the login form is a unit/component. And testing those units/components functionality is known as Unit Testing.ExampleLet's see the basic structure of unittest framework. Live Demo# importing unittest module import unittest # unittest will test ... Read More

Bypass Anti-virus using Veil Framework

Ajay yadav
Updated on 20-Apr-2020 06:03:20

1K+ Views

This article is intended to demonstrate, how to bypass the anti-virus detection using the Veil framework, as it is a collection of tools designed for use during penetration testing. It currently consists of the following modules −Veil-Evasion − a tool to generate antivirus-evading payloads using a variety of techniques and languagesVeil-Catapult − a psexec-style payload delivery system that integrates Veil-EvasionVeil-PowerView − a powershell tool to gain network situational awareness on Windows domainsVeil-Pillage − a modular post-exploitation framework that integrates Veil-EvasionRequirementsTo install the Veil- Framework, you are supposed to configure the latest Python packages into your machine.How to InstallThe important point ... Read More

Difference between Python and Bash

Mahesh Parahar
Updated on 16-Apr-2020 06:20:19

1K+ Views

PythonPython is a programing language designed to be simple to implement and easy to understand. It is a dynamically typed language. It is not using pointers.BashBash is a command-line interpreter and is shipped by default in Linux and MacOS operating systems. It can be installed in other operating systems as well. It is default User Shell for Linux and MacOS.The following are some of the important differences between Python and Bash.Sr. No.KeyPythonBash1TypePython is a programming language mostly used in automation programming.Bash is a command-line interpreter or user shell to interpret user commands.2BasisPython is developed as an easy to implement an ... Read More

Advertisements