String In Python
Rushikesh J.
QA Automation Engineer @Vinz Global | Robot Framework | Manual Testing, Automation Testing | Python | Selenium | GIT | JIRA | Immediate Joiner | API Testing Using Postman | Jenkins
String Data Type in Python
How To Create String
Examples:
str1 = “Rushikesh Jethure”
str2 = “238843” # numeric string
str3 = “Rushikesh123” # alpha numeric string
str3? =? “True” # Boolean string
Access String (Element)
We can access string element using different way
Example:
str = “Rushikesh jethure”
1) Using variable method
e.g? print(str)
2) Using array method
e.g print(str[index number])
3) Using slice method
e.g print(str[starting index, ending point])
4) Using for loop method
str = “Rushikesh jethure”
for i in str:
? print(i)
Iterate String Using For Loop
We can iterate string items using for loop to access any specific items or to check any specific item in a string at specific location (index number)
Iterate means, we can get items of sequence data type one by one.
Example:
str = “Rushikesh”
for i in str:
? print(i)
R
u
s
h
i
k
e
s
h
List Of String Methods in Python
capitalize()?
casefold()?
center()?
count()?
encode()?
endswith()?
expandtabs()?
find()?
format()?
format_map()?
index()
isalnum()?
isalpha()?
isascii()?
isdecimal()?
isdigit()?
isidentifier()?
islower()?
isnumeric()
isprintable()?
isspace()?
istitle()?
isupper()?
join()?
ljust()?
lower()?
lstrip()?
maketrans()?
partition()?
replace()
rfind()?
rindex()?
rjust()?
rpartition()?
rsplit()?
rstrip()?
split()?
splitlines()?
startswith()?
strip()?
swapcase()?
title()?
translate()?
upper()?
zfill()?