
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 26504 Articles for Server Side Programming

184 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

769 Views
You can either remove individual dictionary elements or clear the entire contents of a dictionary. You can also delete entire dictionary in a single operation.To explicitly remove an entire dictionary, just use the del statement.ExampleFollowing is a simple example − Live Demo#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name']; # remove entry with key 'Name' dict.clear(); # remove all entries in dict del dict ; # delete entire dictionary print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['School']OutputThis produces the following result. Note that an exception is raised because after del dict dictionary does not exist any more −dict['Age']: Traceback (most ... Read More

667 Views
You can update a dictionary by adding a new entry or a key-value pair, modifying an existing entry, or deleting an existing entry as shown below in the simple example −Example Live Demo#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} dict['Age'] = 8; # update existing entry dict['School'] = "DPS School"; # Add new entry print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['School']OutputWhen the above code is executed, it produces the following result −dict['Age']: 8 dict['School']: DPS School

2K+ Views
Accessing Values of Dictionary in Python Accessing dictionary items in Python involves retrieving the values associated with specific keys within a dictionary data structure. Dictionaries are composed of key-value pairs, where each key is unique and maps to a corresponding value. Accessing dictionary items allows us to retrieve these values by providing the respective keys. There are various ways to access dictionary items in Python. They include − Using square brackets[] The get() method Using keys() Method Using values() Method ... Read More

9K+ Views
Python includes the following tuple functions −Sr.NoFunction with Description1cmp(tuple1, tuple2)Compares elements of both tuples.2len(tuple)Gives the total length of the tuple.3max(tuple)Returns item from the tuple with max value.4min(tuple)Returns item from the tuple with min value.5tuple(seq)Converts a list into tuple.

297 Views
Any set of multiple objects, comma-separated, written without identifying symbols, i.e., brackets for lists, parentheses for tuples, etc., default to tuples, as indicated in these short examples −Example Live Demo#!/usr/bin/python print 'abc', -4.24e93, 18+6.6j, 'xyz'; x, y = 1, 2; print "Value of x , y : ", x,y;OutputWhen the above code is executed, it produces the following result −abc -4.24e+93 (18+6.6j) xyz Value of x , y : 1 2

478 Views
Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string.In fact, tuples respond to all of the general sequence operations we used on strings in the prior chapter −Python ExpressionResultsDescriptionlen((1, 2, 3))3Length(1, 2, 3) + (4, 5, 6)(1, 2, 3, 4, 5, 6)Concatenation('Hi!',) * 4('Hi!', 'Hi!', 'Hi!', 'Hi!')Repetition3 in (1, 2, 3)TrueMembershipfor x in (1, 2, 3): print x,1 2 3Iteration

8K+ Views
Removing individual tuple elements is not possible. There is, of course, nothing wrong with putting together another tuple with the undesired elements discarded.To explicitly remove an entire tuple, just use the del statement.Example Live Demo#!/usr/bin/python tup = ('physics', 'chemistry', 1997, 2000); print tup; del tup; print "After deleting tup : "; print tup;OutputThis produces the following result. Note an exception raised, this is because after del tup tuple does not exist any more −('physics', 'chemistry', 1997, 2000) After deleting tup : Traceback (most recent call last): File "test.py", line 9, in print tup; NameError: name 'tup' is not defined