Skip to main content

Posts

Showing posts from August, 2020

How to get a current time and date using pyhton ?

 Here are some examples using datatime module to get current time and date # %% Import necessary library from  datetime  import  date , time , timezone , datetime # %% Run using function .now to get right present time datetime.now() ... datetime.datetime(2020, 8, 31, 11, 23, 42, 962037) # %% dt = datetime.now() dt.strftime( '%c' ) ... 'Mon Aug 31 10:45:55 2020' # %% To get only time t = dt.time() t.strftime( '%r' ) ... '10:45:55 AM' # %% To get only date d = date.today() d.isoformat() ... '2020-08-31' # %% You can also use this for various style a.strftime( '%m-%d' ) # month and date ... '08-31' a.strftime( '%m-%a' ) # month and day '08-Mon'

Collection in python

There are basic two datatypes in python  1. Immutable datatype : numeric , string , tuple 2. Mutable : list , dictionary , set Immutable  : Content cannot be changed or modified using the indexing operator ( assignment  statement ) Mutable  : Content can be changed or modified using the indexing operator ( assignment  statement ) Numeric : int, float , complex numbers Sequence : list, string, tuple, range Mapping : dictionary Set : set , frozenset Boolean : is used for making more conditions for 'if' in True and False form Collections in python : 1) Dictionary : It is used to map arbitrary keys to value Only immutable ( content can be changed ) objects can be used as keys to dictionaries Ex :  D = { 'a' : 10 , 'b' : [20, 30] }                   2)  List : It can collect multiple values, multiple types of objects and data collection in single variable.  It is mutable. So...