Ticker

6/recent/ticker-posts

strings in python for beginners at home (2021 grasp basic python online with role model)

Strings in python for beginners at home  (2021 grasp basic python online with role model)

 

strings in python for beginners at home



Strings in Python: 

The Strings can be simply defined as the information that was provided between the  ( " " )  and it will be displayed by using the print () function 

-> Both the single quotation and double quotation marks are used for the string 

Example: 

"Hello world"  is the same as the 'Hello world'  

print("Hello")
print('Hello') 

Output: Hello
             Hello



Assign a string to the variable:

In the Python programming language, we can assign a string to a variable 

Example

a = " Ram"
print( a)

Output: Ram 

Multiline strings: 

In the python language, the string can be a single line and it can also be in multiple lines we just need to enter the info in between the quotations then it will be accepted  as a string 

-> But while using the multiline strings we need to use the three quotes ("""     """)


Example: 

A = "" Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque"""

print(A)


String Length () : 

To know the length of a particular string we just need to use the function len()


Example:

b = "Hello, World!"
print(len(b))

output: 13


Slicing the strings: 

The slicing is nothing but it a feature that enables the accessing the part of the string 

Example: 

b = "Hello, World!"
print(b[:5])

output: Hello, world!


Modifying the Strings: 

We can modify the string that we use in both upper case and lower case we just have to sue the Upper() and lower() functions 

Example: 
 
A = ( "ramesh is good boy" ) #here we have used the upper() function 
print(a.upper())

output: RAMESH IS A GOOD BOY 

Example 2: 

A =  (" SURESH IS A GOOD BOY")  #here we have used the lower() function
printt(A.lower())

output: Suresh is a good boy 

Post Navi

Post a Comment

0 Comments