Program to reverse a string
String = "My name is Miguel."
print(String[::-1])
Python String join() Method
The join() method takes all items in an iterable and joins them into one string. A string must be specified as the separator.
Deleting a String with the use of del
del String
Escape Sequencing of String
String = 'I/'m Miguel.'
print(String)
Using raw String to ignore Escape Sequences
String1 = r"This is /x47/x65/x65/x6b/x73 in /x48/x45/x58"
print(String1)
Formatting of Strings
# Default order
String1 = "{} {} {}".format('Geeks', 'For', 'Life')
print("Print String in default order: ")
print(String1)
# Positional Formatting
String1 = "{1} {0} {2}".format('Geeks', 'For', 'Life')
print("/nPrint String in Positional order: ")
print(String1)
# Keyword Formatting
String1 = "{l} {f} {g}".format(g='Geeks', f='For', l='Life')
print("/nPrint String in order of Keywords: ")
print(String1)
Integers such as Binary, hexadecimal, etc., and floats can be rounded or displayed in the exponent form with the use of format specifiers.
# Formatting of Integers
String1 = "{0:b}".format(16)
print("/nBinary representation of 16 is ")
print(String1)
# Formatting of Floats
String1 = "{0:e}".format(165.6458)
print("/nExponent representation of 165.6458 is ")
print(String1)
# Rounding off Integers
String1 = "{0:.2f}".format(1/6)
print("/none-sixth is : ")
print(String1)
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/277183.html