Found 33676 Articles for Programming

Global and Local Variables in Python?

Arjun Thakur
Updated on 31-Aug-2023 02:52:46

13K+ Views

There are two types of variables: global variables and local variables. The scope of global variables is the entire program whereas the scope of local variable is limited to the function where it is defined.Example def func(): x = "Python" s = "test" print(x) print(s) s = "Tutorialspoint" print(s) func() print(x) OutputIn above program- x is a local variable whereas s is a global variable, we can access the local variable only within the function it is defined (func() above) and ... Read More

Counters in Python?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

4K+ Views

A Counters is a container which keeps track to how many times equivalent values are added. Python counter class is a part of collections module and is a subclass of dictionary.Python CounterWe may think of counter as an unordered collection of items where items are stored as dictionary keys and their count as dictionary value.Counter items count can be positive, zero or negative integers. Though there is no restrict on its keys and values but generally values are intended to be numbers but we can store other object types too.InitializingCounter supports three forms of initialization. Its constructor can be called ... Read More

Time Functions in Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

15K+ Views

Python provides library to read, represent and reset the time information in many ways by using “time” module. Date, time and date time are an object in Python, so whenever we do any operation on them, we actually manipulate objects not strings or timestamps.In this section we’re going to discuss the “time” module which allows us to handle various operations on time.The time module follows the “EPOCH” convention which refers to the point where the time starts. In Unix system “EPOCH” time started from 1 January, 12:00 am, 1970 to year 2038.To determine the EPOCH time value on your system, ... Read More

Transpose a matrix in Python?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

3K+ Views

Transpose a matrix means we’re turning its columns into its rows. Let’s understand it by an example what if looks like after the transpose.Let’s say you have original matrix something like -x = [[1, 2][3, 4][5, 6]]In above matrix “x” we have two columns, containing 1, 3, 5 and 2, 4, 6.So when we transpose above matrix “x”, the columns becomes the rows. So the transposed version of the matrix above would look something like -x1 = [[1, 3, 5][2, 4, 6]]So the we have another matrix ‘x1’, which is organized differently with different values in different places.Below are couple ... Read More

Ternary Operator in Python?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

11K+ Views

Many programming languages support ternary operator, which basically define a conditional expression.Similarly the ternary operator in python is used to return a value based on the result of a binary condition. It takes binary value(condition) as an input, so it looks similar to an “if-else” condition block. However, it also returns a value so behaving similar to a function.Syntax[on_true] if [expression] else [on_false]Let’s write one simple program, which compare two integers -a. Using python if-else statement ->>> x, y = 5, 6 >>> if x>y:    print("x") else:    print("y") yb. Using ternary operator>>> x, y = 5, 6 >>> ... Read More

What is the use of cin.ignore() in C++?

Nishu Kumari
Updated on 11-Jun-2025 15:09:43

67K+ Views

In C++, cin.ignore() is a built-in function that belongs to the istream class and is defined in the header. It is used to skip characters left in the input buffer, especially the newline character (''), which can cause issues with input operations like getline(). In this article, we will explain the use of cin.ignore() in C++. Syntax of cin.ignore() Below is the syntax of the cin.ignore() function. cin.ignore(numeric_value, delimiter_char); // Example: cin.ignore(1000, ''); Here, numeric_value is the maximum number of characters to skip, and delimiter_char is the character at which the input should stop ... Read More

How to write a singleton class in C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

1K+ Views

Singleton design pattern is a software design principle that is used to restrict the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. For example, if you are using a logger, that writes logs to a file, you can use a singleton class to create such a logger. You can create a singleton class using the following code.Example#include using namespace std; class Singleton {    static Singleton *instance;    int data;    // Private constructor so that no objects can be created.    Singleton() {   ... Read More

What is volatile keyword in C++?

Akansha Kumari
Updated on 15-Jul-2025 17:06:41

12K+ Views

C++ Volatile KeywordIn C++, the volatile keyword is a type qualifier that tells the compiler that the value of a variable may be changed at any time unexpectedly, so it should not optimize access to that variable. This change in a variable may be influenced by any external factors such as hardware, signal handlers, or concurrent threads. This concept of volatile is mostly used when working with systems programming, embedded systems, and multi-threaded applications. SyntaxHere, a variable is declared volatile, which means the compiler volatile data_type variable_name; Example This example represents a variable whose value may be changed from an external source. ... Read More

What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__ in C/C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

Here we will see what are the differences between __FUNCTION__, __func__ and the __PRETTY_FUNCTION__ in C++.Basically the __FUNCTION__ and __func__ are same. Some old versions of C and C++ supports __func__. This macro is used to get the name of the current function. The _PRETTY_FUNCTION__ is used to return the detail about the function. Using this we can get which function is used, and in which class it is belonging, etc.Example#include using namespace std; class MyClass{    public:       void Class_Function(){          cout

What is a reentrant function in C/C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

4K+ Views

Here we will see what is the reentrant function in C or C++. One function is said to be a reentrant function if there is a provision to interrupt that function in the course of execution, then service the ISR (Interrupt Service Routine) and then resume the task. This type of functions is used in different cases like, recursions, hardware interrupt handling.For a reentrant function there should be some properties. These are listed below −This type of function will not use any global or static variable. There are no restrictions, but it is generally not advised. This is because the ... Read More

Advertisements