
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

11K+ Views
In Python Call by Value and Call by Reference are two types of generic methods to pass parameters to a function. In the Call-by-value method, the original value cannot be changed, whereas in Call-by-reference, the original value can bechanged. Call by Value in Python When we pass an argument to a function, it is stored locally (in the stack memory), i.e the scope of these variables lies with in the function and these will not have effect the values of the golbal variables (variables outside function). In Python, "passing by value" is possible only with the immutable types such as integers, floats, strings, ... Read More

506 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 is the example to call printme() function − Live Demo#!/usr/bin/python # Function definition is here def printme( str ): "This prints a passed string into this function" print str return; # Now you can call printme function printme("I'm first call to user defined function!") printme("Again second call to the same function")OutputWhen ... Read More

592 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 −Sr.NoFunction with Description1calendar.calendar(year, w=2, l=1, c=6)Returns a multiline string with a calendar for year year formatted into three columns separated by c spaces. w is the width in characters of each date; each line has length 21*w+18+2*c. l is the number of lines for each week.2calendar.firstweekday( )Returns the current setting ... Read More

477 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 local DST timezone is east of UTC (as in Western Europe, including the UK). Only use this if daylight is nonzero.2time.asctime([tupletime])Accepts a time-tuple and returns a readable 24-character string such as 'Tue Dec 11 18:07:14 2008'.3time.clock( )Returns the current CPU time as a floating-point number of seconds. To measure computational ... Read More

1K+ Views
Appending a Python script to windows start-up basically indicates the python script will run as the windows boots up. This can be accomplished by two step processes -Step #1: Appending or Adding script to windows Startup folderAfter booting up of the windows, it executes (equivalent to double-clicking) all the application present in its startup folder or directory.AddressC:\Users\current_user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\By default, the AppData directory or folder under the current_user is hidden that enable hidden files to get it and paste the shortcut of the script in the given address or the script itself. Besides this the .PY files default must be set ... Read More

489 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

222 Views
To translate a time instant from a seconds since the epoch floating-point value into a time-tuple, pass the floating-point value to a function (e.g., localtime) that returns a time-tuple with all nine items valid.Example Live Demo#!/usr/bin/python import time; localtime = time.localtime(time.time()) print "Local current time :", localtimeOutputThis would produce the following result, which could be formatted in any other presentable form −Local current time : time.struct_time(tm_year=2013, tm_mon=7, tm_mday=17, tm_hour=21, tm_min=26, tm_sec=3, tm_wday=2, tm_yday=198, tm_isdst=0)

183 Views
Many of Python's time functions handle time as a tuple of 9 numbers, as shown below −IndexFieldValues04-digit year20081Month1 to 122Day1 to 313Hour0 to 234Minute0 to 595Second0 to 61 (60 or 61 are leap-seconds)6Day of Week0 to 6 (0 is Monday)7Day of year1 to 366 (Julian day)8Daylight savings-1, 0, 1, -1 means library determines DSTThe above tuple is equivalent to struct_time structure. This structure has following attributes −IndexAttributesValues0tm_year20081tm_mon1 to 122tm_mday1 to 313tm_hour0 to 234tm_min0 to 595tm_sec0 to 61 (60 or 61 are leap-seconds)6tm_wday0 to 6 (0 is Monday)7tm_yday1 to 366 (Julian day)8tm_isdst-1, 0, 1, -1 means library determines DSTRead More

13K+ Views
Python includes the following dictionary functions −Sr.NoFunction with Description1cmp(dict1, dict2)Compares elements of both dict.2len(dict)Gives the total length of the dictionary. This would be equal to the number of items in the dictionary.3str(dict)Produces a printable string representation of a dictionary4type(variable)Returns the type of the passed variable. If passed variable is dictionary, then it would return a dictionary type.Python includes following dictionary methods −Sr.NoMethods with Description1dict.clear()Removes all elements of dictionary dict2dict.copy()Returns a shallow copy of dictionary dict3dict.fromkeys()Create a new dictionary with keys from seq and values set to value.4dict.get(key, default=None)For key key, returns value or default if key not in dictionary5dict.has_key(key)Returns true ... Read More

4K+ Views
Dictionary values have no restrictions. They can be any arbitrary Python object, either standard objects or user-defined objects. However, same is not true for the keys.There are two important points to remember about dictionary keys −More than one entry per key not allowed. Which means no duplicate key is allowed. When duplicate keys encountered during assignment, the last assignment wins.ExampleFollowing is a simple example − Live Demo#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Name': 'Manni'} print "dict['Name']: ", dict['Name']OutputWhen the above code is executed, it produces the following result −dict['Name']: Manni Keys must be immutable. Which means you can use strings, ... Read More