Server Side Programming Articles - Page 2237 of 2650

vars() function in Python

Syed Javed
Updated on 30-Jun-2020 08:13:57

728 Views

vars() function belongs to the collection of inbuilt functions provided by the Python standard library. It returns the __dic__ attribute of an associated object to the console.Syntaxvars(object)Return TypeParametersvars() function accepts only one parameter. It takes an object as its parameter which can be any module, class or any object having __dict__ attribute associated with it.This parameter is optional in nature. In case the function is used without parameters A dictionary containing local symbol table is displayed.Exceptions InvolvedIf the argument passed doesn’t match the attribute, it raises the TypeError exception.ScopeVars() acts like locals() method when no argument is passed.The locals() method ... Read More

Python zip() Function

Akshitha Mote
Updated on 22-Jan-2025 14:28:28

657 Views

The zip() function in Python is used to map elements from multiple iterables at corresponding index positions. It returns an iterator of tuples, where each tuple contains elements from the input iterables at the same index. Suppose the lengths of the input iterables are not the same. In that case, the zip() function will stop pairing once the shortest iterable is exhausted, ignoring any extra elements from the longer iterables. Following is the syntax of the zip() function in Python − zip(iterable1, iterable2) It accepts iterables as a parameter and returns a single iterable. Using zip() with list list ... Read More

Custom len() Function In Python

Hafeezul Kareem
Updated on 30-Jul-2019 22:30:26

820 Views

Let's see how can we implement custom len() function in Python. Try it by yourself first using the following steps.StepsGet the iterator from the user string/list/tuple.Define a function with a custom name as you like and invoke it by passing the iterator.Initialize the count to 0.Run a loop until it reaches the end.Increment the count by 1Return the count.Example Live Demo## function to calculate lenght of the iterator def length(iterator):    ## initializing the count to 0    count = 0    ## iterating through the iterator    for item in iterator:       ## incrementing count       ... Read More

Why importing star is a bad idea in python

Hafeezul Kareem
Updated on 29-Jun-2020 14:05:12

519 Views

Importing all methods from a module in Python is a bad idea because of the following reasons.It is difficult to find a parent module of the method which we used in the programs.We are not allowed to create our functions with the names of methods.Let's see an example. Below we write a function called add in the sample.py.## sample.py file def add(a, b): return a + bExampleSave the above file in the same directory as below Python file.## let's assume we have module called sample from sample import * def add(*nums):    return sum(nums) print(add(1, 2, 3, 4, ... Read More

Ways to print escape characters in python

Hafeezul Kareem
Updated on 30-Jul-2019 22:30:26

4K+ Views

In this article, we are going to see how we can print the escape characters in Python. I think you know what escape characters are? Let's see what escape characters for those who don't know are?Escape characters are used for the individual meanings in strings. If we want to include a new line, tab space, etc., in strings, we can use these escape characters. Let's see some examples.Example Live Demo## new line new_line_string = "HiHow are you?" ## it will print 'Hi' in first line and 'How are you?' in next line print(new_line_string)OutputIf you run the above program, it will ... Read More

Ways to increment a character in python

Hafeezul Kareem
Updated on 29-Jun-2020 13:48:16

12K+ Views

In this tutorial, we are going to see different methods to increment a character in Python.TypecastingLet's first see what happens if we add an int to char without typecasting.Example Live Demo## str initialization char = "t" ## try to add 1 to char char += 1 ## gets an errorIf you execute above program, it produces the following result −TypeError          Traceback (most recent call last) in ()       3     4 ## try to add 1 to char ----> 5 char += 1 ## gets an error TypeError: must be str, not intTo ... Read More

Differentiate between exception and error in PHP

Alok Prasad
Updated on 29-Jun-2020 12:48:40

2K+ Views

Let's discuss the differences between errors and exceptions.Recovering from Error is not possible. The only solution to errors is to terminate the execution. Whereas we can recover from Exception by using either try-catch blocks or throwing an exception back to the caller.You will not be able to handle the Errors using try-catch blocks. Even if you handle them using try-catch blocks, your application will not recover if they happen. On the other hand, Exceptions can be handled using try-catch blocks and can make program flow normally if they happen.Exceptions are related to the application whereas Errors are related to the ... Read More

Is PHP compiled or interpreted?

Alok Prasad
Updated on 29-Jun-2020 12:49:09

3K+ Views

Basically, PHP is interpreted but PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime Zend engine.PHP compiler is responsible forconvert the code to a bytecode that can be used by the runtime engine.resolve functions, names and classes namescreating a symbol tablePHP Interpreter doesGoes through the bytecode line by line and executes itHandles runtime exception

What is the use of ini_set() in PHP?

Alok Prasad
Updated on 29-Jun-2020 12:50:11

6K+ Views

PHP allows the user to modify some of its settings mentioned in php.ini using ini_set(). This function requires two string arguments. The first one is the name of the setting to be modified and the second one is the new value to be assigned to it.Parametersvar nameNot all the available options can be changed using ini_set(). There is a list of all available options in the appendix.new valueThe new value for the option.ExampleGiven the line of code will enable the display_error setting for the script if it’s disabled. We need to put the above statement, at the top of the ... Read More

What is the meaning of a Persistent Cookie in PHP?

Alok Prasad
Updated on 29-Jun-2020 12:04:35

1K+ Views

A persistent cookie is a cookie that is stored in a cookie file permanently on the browser's computer. As we know cookies are small text files which are as a matter, of course, temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased from the memory.When to use persistent cookies −Temporary cookies can not be used for tracking long-term information.Persistent cookies can be used for tracking long-term information.Temporary cookies are safer because no programs other than the browser can access them.Persistent cookies are less secure because users can open cookie files ... Read More

Advertisements