Python | Strings


python string,python string functions
python string


Python | string

  • string is Sequence of characters
  • string is Written between quotation (Single or Double) mark. like ' Hello ' or " Hello "

How to create a string in Python?

  •     String can be created by set of characters  in side single or double Quote
  •     String is Print With print() Function


Example

    print("Hello")


Output
    
    Hello


String with Variable :

Variable is a one type of container that could be store some Value

String Assign in Variable 


Example

    str = " Hello "

    print(str)


Output

    Hello



Multiline string 

Multiline string you can define in Single triple quote or Double triple quote


Example - 1

Single triple quote 

    Address = ''' 123 Main Street,

                        Near to XYZ Bank,  

                        New York,

                        NY 10030 '''

    print(Address)



Output 

                       123 Main Street,
                        Near to XYZ Bank,  

                        New York,

                        NY 10030 

Example - 2

Double triple Quote

    Address = """ 123 Main Street,

                        Near to XYZ Bank,  

                        New York,

                        NY 10030 """

      print(Address)



Output

                        123 Main Street,

                        Near to XYZ Bank,  

                        New York,

                        NY 10030



String : Get Length 

You can get the Length of String using len() function 

Example  

     str = "Python"
    
    print(len(str))    


Output

 return 6 is length of variable ' A ' 




Staring : Concatenating 

To combine , merge  of two string  you can use +  Operator

Example

        str1 = 'john'
        str2 ='doe' 
        print(str1+" "+str2)               

Output

    john doe 


Also See

Post a Comment (0)
Previous Post Next Post