Programming Articles - Page 1984 of 3366

Program to print its script name as output in Python

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

1K+ 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

406 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

364 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

941 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

List in C++(4.5)

Sunidhi Bansal
Updated on 24-Apr-2020 12:15:00

167 Views

List are the type of containers that stores data in sequential manner and allocate noncontiguous memory to the elements. In C++, lists are considered as doubly linked list where insertion and deletion of elements can be done from both the ends and therefore, it is also possible to traverse the list from both the end. For using singly linked list we use the forward list available in C++ STL.Advantage of using List over vector is thatList are faster in insertion and deletion of elements available in list container if the iterator is positioned to the correct element.Disadvantage of using List ... Read More

Stack in C++ STL(3.5)

Sunidhi Bansal
Updated on 24-Apr-2020 11:55:29

461 Views

In C++ STL, stack is used as container which is implemented as LIFO structure. LIFO means Last In First Out. Stack can view as a pile of books in which the books are arranged one above the another and the last inserted book will be the first one to be removed that’s why it is called as a LIFO structure.The operations associated with the stack are -Top() - This function returns the reference to the topmost element of a stack.Syntax - name_of_stack.top()Parameters - No ParameterReturn Value - Reference to the topmost element of a stack containerPush() - This function is ... Read More

Functions in C/C++(3.5)

Sunidhi Bansal
Updated on 24-Apr-2020 11:55:57

259 Views

Functions are like a machine as they perform some functionality and produces a result of some type. Like, machine takes some input, process that input and produce an output similarly, function takes some value, operates on those value and produces the output. Manually a person passes the input to the machine then only the machine will start its functionality in the same manner when the programmer calls the function it will start executing.Functions can be different in name in various languages, but they share two common characteristics like −They contain sequence of instructions that needs to be processedThose instructions are ... Read More

How to show reflection frames of StackFrame in Java 9?

raja
Updated on 24-Apr-2020 10:22:23

192 Views

A standard API has been provided in Java 9 using java.lang.StackWalker class. This class designed to be efficient by allowing lazy access to the stack frames. A couple of other options allow in a stack trace that includes implementation and/or reflection frames, and it can be useful for debugging purposes. For instance, we add SHOW_REFLECT_FRAMES option to StackWalker instance upon creation, so that frames for reflective methods are printed as well.In the below example, we can able to show reflection frames of StackFrameExampleimport java.lang.StackWalker.Option; import java.lang.StackWalker.StackFrame; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.stream.Collectors; public class ReflectionFrameTest {    public static ... Read More

How to skip certain classes in StackFrame in Java 9?

raja
Updated on 24-Apr-2020 09:20:53

246 Views

StackWalker API has been introduced in Java 9, and it gives a snapshot of the stack trace of current thread at any given point of time and has methods to walk over it. The advantage of using StackWalker class over Thread::getStackTrace() is to filter or skip certain classes and get the instance of declaring the class itself and get either short stack trace or full stack trace instead of pulling the complete stack trace itself.In the below example, we can use java.util.stream.Stream.skip() method to skip Stack Frames.Exampleimport java.lang.StackWalker.*; import java.util.Optional; import java.util.List; import java.util.stream.Collectors; import java.lang.StackWalker.StackFrame; public class StackWalkerSkipTest {    public ... Read More

How to define a switch statement in JShell in Java 9?

raja
Updated on 23-Apr-2020 18:43:42

191 Views

JShell is based on the REPL (Read-Evaluate-Print-Loop) introduced in Java 9. This tool can be used to execute simple statements, evaluate it, and prints the result.A switch statement can test multiple conditions just like an else clause and handles the default possibility. The default clause can be executed when none of the cases match, and a break statement can be used to break out of switch after a successful match.In the below code snippet, we can define the switch statement in JShell.Snippet-1jshell> int i = 10; i ==> 10 jshell> switch(i) { ...> case 1 ... Read More

Advertisements