Python Strings:
A string is a sequence of characters.
A character is simply a symbol. For example, the English language has 26 characters.
Computers do not deal with characters, they deal with numbers (binary). Even though you may see characters on your screen, internally it is stored and manipulated as a combination of 0s and 1s.
This conversion of character to a number is called encoding, and the reverse process is decoding. ASCII and Unicode are some of the popular encodings used.
In Python, a string is a sequence of Unicode characters. Unicode was introduced to include every character in all languages and bring uniformity in encoding.
How to create a string in Python
single quote or double-quotes. Even triple quotes can be used in Python
How to access characters in a string:
We can access individual characters using indexing and a range of characters using slicing. Index starts from 0. Trying to access a character out of index range will raise an IndexError. The index must be an integer. We can't use floats or other types, this will result into TypeError.
Python allows negative indexing for its sequences.
The index of -1 refers to the last item, -2 to the second last item and so on. We can access a range of items in a string by using the slicing operator :(colon).
If we try to access an index out of the range or use numbers other than an integer, we will get errors.
If we want to access a range, we need the index that will slice the portion from the string.
How to change or delete a string?
Strings are immutable. This means that elements of a string cannot be changed once they have been assigned. We can simply reassign different strings to the same name.
We cannot delete or remove characters from a string. But deleting the string entirely is possible using the del keyword.
Concatenation of Two or More Strings:
Joining of two or more strings into a single one is called concatenation.
The + operator does this in Python. Simply writing two string literals together also concatenates them.
The * operator can be used to repeat the string for a given number of times.
Iterating Through a string:
String Membership Test:
We can test if a substring exists within a string or not, using the keyword in.
Common Python String Methods:
Some of the commonly used methods are lower(), upper(), join(), split(), find(), replace() etc.
Python String Formatting:
If we want to print a text like He said, "What's there?", we can neither use single quotes nor double quotes. This will result in a SyntaxError as the text itself contains both single and double quotes.
ex:
print("He said, "What's there?"")
print('He said, "What's there?"')
One way to get around this problem is to use triple quotes. Alternatively, we can use escape sequences.
An escape sequence starts with a backslash and is interpreted differently. If we use a single quote to represent a string, all the single quotes inside the string must be escaped. Similar is the case with double quotes. Here is how it can be done to represent the above text.
API Automation
➡️ Rest Assured Using Java → • Rest Assured
➡️ Karate Framework using Maven → • Karate Framework Using Maven Project
Programing Language
Basic Python → • Basic Python
➡️ Core Java → • CoreJava
Performances Testing
➡️ JMeter Beginner → • JMeter Beginner
➡️ Locust Beginner → • Locust
Git and GitHub
➡️ Git and GitHub Beginner → • Git and GitHub Beginner
Manual Testing
➡️ Manual Testing → • Manual Testing
Automation Testing
➡️ Selenium Cucumber Framework using Java → • Selenium Cucumber BDD Framework with ...
➡️ Robot Framework with Python → • Python With Robot Framework
➡️ Beginner Karate Framework using Intellij → • Karate Framework Beginner
➡️ Karate Framework with Gradle using eclipse → • Karate Framework using Gradle Project
➡️ Basic Selenium WebDriver using Java → • Selenium WebDriver
➡️ TestNG Framework → • TestNG Framework
➡️ Robot Framework with RIDE → • RIDE With Robot Framework
________________ Beginner Jenkins ____________________
➡️ Beginner Jenkins → • Beginner Jenkins
Watch video Basic Python 34: Python Strings online, duration hours minute second in high quality that is uploaded to the channel Testing Tutorialspoint 11 October 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 29 times and liked it 7 visitors.