.find() - Python Automation and Machine Learning for ICs - - An Online Book: Python Automation and Machine Learning for ICs by Yougui Liao - |
||||||||
Python Automation and Machine Learning for ICs http://www.globalsino.com/ICs/ | ||||||||
Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix | ||||||||
================================================================================= The .find() method in Python is used to locate the position of a substring within a string. It returns the index of the first occurrence of the substring. If the substring is not found, it returns -1. =========================================== Find an element in a string. Code: Output:
=========================================== string.find(substring, start, end): Start the search from index 10 and end at index 30. Code:
=========================================== str.format() is another way to format strings in Python. It uses curly braces {} as placeholders for variables which are passed as arguments in the format() method. Code:
=========================================== % Operator is one of the oldest ways to format strings in Python. It uses the % operator to replace variables in the string. Code:
=========================================== F-strings are also able to evaluate expressions inside the curly braces, which can be very handy. Code:
=========================================== ===========================================
|
||||||||
================================================================================= | ||||||||
|
||||||||