Python string functions
string_name.upper() // to change all letter to upper case
string_name.lowe() // to change all letters to lower
string_name.len() // returns the length of string.
string_name.find("string to be founded") // if not present than return -1 else returns the index position (0-based)
in function is a boolean variables that returns True or false.
Ex. course="python for programmers";
print("python" in course);
output : True.
//Note : The boolean variables are case sensitive, i.e, True is correct but true is useless, same False is correct but false is useless.
string_name.replace("string to be replaced","new string") // replaces only when string to be replaced is found.
Formatted strings - f ' --{}---{}---'
These can be used to print stings with values of variables like;
Ex-
first= 'Ram' ;
last = 'mango' ;
msg= f ' Hello {first}, is this {last} your favourite fruit ' ;
print(msg);
output :
Hello Ram, is this mango your favourite fruit
These { } are the place holders for variables or holes in string to store value of variables
Comments
Post a Comment