Python data structure basics
2022/7/27 14:24:06
本文主要是介绍Python data structure basics,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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)
这篇关于Python data structure basics的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南