Mohd Mohtashim has Published 251 Articles

Getting current time in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 13:03:37

116 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 ... Read More

What is TimeTuple in Python?

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 13:02:37

128 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 ... Read More

Built-in Dictionary Functions & Methods in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 13:01:09

9K+ 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, ... Read More

Properties of Dictionary Keys in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 13:00:22

3K+ 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. ... Read More

Delete Dictionary Elements in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 12:59:30

531 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']; # ... Read More

Updating Dictionary in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 12:50:23

426 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 ... Read More

Accessing Values of Dictionary in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 12:49:38

2K+ Views

To access dictionary elements, you can use the familiar square brackets along with the key to obtain its value.ExampleFollowing is a simple example − Live Demo#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} print "dict['Name']: ", dict['Name'] print "dict['Age']: ", dict['Age']OutputWhen the above code is executed, it produces the following ... Read More

Built-in Tuple Functions in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 12:48:46

8K+ 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.Read More

No Enclosing Delimiters in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 12:48:06

194 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 ... Read More

Basic Tuples Operations in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 28-Jan-2020 12:47:24

347 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, ... Read More

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