Posts

Showing posts from April, 2022

Python Notes - Strings

Python Notes String Methods string.capitalize() Capitalized first letter of string. string.strip() Strips whitespaces both left and right side. string.lstrip() Strips whitespaces left side string.rstrip() Strips whitespaces right side string.lower() turns string into lower case string.upper() turns string into upper case string.split() Split string into array String Formatting Formatting using %{s,i} In [24]: import time In [25]: time.strftime("%H:%M:%S") Out[25]: '21:19:12' In [26]: # Method 1 In [27]: print("Hello %s, current time is %s" % ("Raja", time.strftime("%H:%M:%S"))) Hello Raja, current time is 21:20:22 In [28]: # Method 2 In [30]: print("Hello %(name)s, current time is %(time_now)s" % { "name"