Mohd Mohtashim has Published 251 Articles

Namespaces and Scoping in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 06:28:56

393 Views

Variables are names (identifiers) that map to objects. A namespace is a dictionary of variable names (keys) and their corresponding objects (values).A Python statement can access variables in a local namespace and in the global namespace. If a local and a global variable have the same name, the local variable shadows the global variable.Each function ... Read More

Locating Modules in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 06:28:14

981 Views

When you import a module, the Python interpreter searches for the module in the following sequences −The current directory.If the module isn't found, Python then searches each directory in the shell variable PYTHONPATH.If all else fails, Python checks the default path. On UNIX, this default path is normally /usr/local/lib/python/.The module ... Read More

The Anonymous Functions in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 06:20:22

2K+ Views

These functions are called anonymous because they are not declared in the standard manner by using the def keyword. You can use the lambda keyword to create small anonymous functions.Lambda forms can take any number of arguments but return just one value in the form of an expression. They cannot contain commands or multiple ... Read More

Variable-length arguments in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 06:19:40

5K+ Views

You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable-length arguments and are not named in the function definition, unlike required and default arguments.SyntaxSyntax for a function with non-keyword variable arguments is this −def functionname([formal_args, ] *var_args_tuple ): "function_docstring" function_suite ... Read More

Required arguments in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 06:14:12

5K+ Views

Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.To call the function printme(), you definitely need to pass one argument, otherwise it gives a syntax error as follows −Example Live Demo#!/usr/bin/python # ... Read More

Pass by reference vs value in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Jan-2020 11:11:15

7K+ Views

All parameters (arguments) in the Python language are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function.Example Live Demo#!/usr/bin/python # Function definition is here def changeme( mylist ): "This changes a passed list into this ... Read More

Calling a Function in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Jan-2020 11:10:26

255 Views

Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code.Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following ... Read More

The calendar Module in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Jan-2020 11:09:25

447 Views

The calendar module supplies calendar-related functions, including functions to print a text calendar for a given month or year.By default, calendar takes Monday as the first day of the week and Sunday as the last one. To change this, call calendar.setfirstweekday() function.Here is a list of functions available with the calendar module ... Read More

The time Module in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Jan-2020 11:08:47

307 Views

There is a popular time module available in Python which provides functions for working with times and for converting between representations. Here is the list of all available methods −Sr.NoFunction with Description1time.altzoneThe offset of the local DST timezone, in seconds west of UTC, if one is defined. This is negative if the ... Read More

Getting formatted time in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 13:05:46

327 Views

You can format any time as per your requirement, but simple method to get time in readable format is asctime() −Example Live Demo#!/usr/bin/python import time; localtime = time.asctime( time.localtime(time.time()) ) print "Local current time :", localtimeOutputThis would produce the following result −Local current time : Tue Jan 13 10:17:09 2009 Read More

Previous 1 ... 5 6 7 8 9 ... 26 Next
Advertisements