Python String (part I)

Strings

What is strings ?

A String is a type of data used in programming, such as a number and a floating point unit, but is used to represent text rather than numbers. ... For example, the word "kavib" and the phrase "I am kavib" are both strings . Even "373822" can be considered a string if specified correctly.

In python, The string should be between single quotes or double-quotes.
Strings can print using print() function

print 'hello world'

print "hello world"



Assign to a Variable

You can assign strings to a variable using the = operator.


    a = 'hello world'
    print(a)


Multiline Strings

In python, we can assign multiline strings using triple quotes.



a="""hello world
        hello country
        hi there"""

a='''hello world
        hello country
        hi there'''


Looping via Strings

In Python, you can loop, via characters in a string using for loop.



for x in 'kavib'
    print(x)

Check string and Check if NOT


check string is used to, check specific phrase is present in the given string

a = 'this is www.kavib.com'
print('is' in a)




check string is used to, check specific phrase is not in the given string

a = 'this is www.kavib.com'
print('is' not in a)





.............................................................................End.........................................................................

see you soon with String part II
follow my blog 
Thank you
KaviB

Comments

  1. The article you've shared here is fantastic because it provides some excellent information that will be incredibly beneficial to me. Thank you for sharing that. Keep up the good work. techwindow.net

    ReplyDelete

Post a Comment

Popular posts from this blog

Review about Dell Laptops

Digital clock using python tkinter