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

Popular posts from this blog

First_Come_First_Serve CPU Scheduling

Reversing stack Method 2 !! (One Helper Stack only)

Populating Next Right Pointers in Each Node in O(1) space (without queue and level order)

Calculate factorial of large numbers !! (Using Arrays)

Multiplication of large numbers (Given in string format)

Left View of Binary Tree (Method 1 using recursion)

Check Bracket Sequence

Image Multiplication

Boundary Traversal of binary tree

BST to greater sum tree