Python Automation and Machine Learning for EM and ICs

An Online Book, Second Edition by Dr. Yougui Liao (2019)

Python Automation and Machine Learning for EM and ICs - An Online Book

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

.find()

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:

 

Output:

===========================================

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:

 

Output:

===========================================

% Operator is one of the oldest ways to format strings in Python. It uses the % operator to replace variables in the string.  Code:

 

Output:

===========================================

F-strings are also able to evaluate expressions inside the curly braces, which can be very handy. Code:

 

Output:

===========================================

code.

===========================================