Comments in Python are the lines in the code that are ignored by the compiler during the execution of the program.
- Single Line Comment (#)
A single-line comment begins with a hash (#) symbol. The single-line comment is used to comment only one line of the code.
#This is sample program
print("roadtocode4u")- Multiline Comment (""" """)
In Python Triple double quote (""") and single quote (''') are used for Multi-line commenting.Multi-line comment is useful when we need to comment on many lines.
"""
This is a comment
written in
more than just one line
"""
print("roadtocode4u")- Upper()
Converts a string into upper case.
myString="roadtocode4u"
newString=myString .upper()
print(newString)- Lower()
Converts a string into lower case.
myString="ROADTOCODE4U"
newString=myString .lower()
print(newString)- Strip()
Removes white space from the end of String
str1="ROADTOCODE4U"
str2="ROADTOCODE4U "
print(str1)
print(str2.strip())- Replace()
Replace in string
myString="roadtocode4u"
newString=myString.replace("o","#")
print(newString)- split()
Splits the string at the specified separator, and returns a list.
student="Harshada,Aniket,Prachi,Anjali"
print(student.split(','))Collection of similar data type
myString="India"
print(myString[2])An escape character is a backslash \ followed by the character you want to insert.
sentence="I\'m Good .She said , How Are You ?"
print(sentence)1️⃣Write a program to implement upper(), lower(), strip() and replace() function on given string.
👁 Show Answer
# Upper
name="Vedika"
newString=name.upper()
print(newString)
# Lower
name="VEDIKA"
newString=name.lower()
print(newString)
#Strip
name1="Vedika"
name2="Vaibhavi "
print(name1)
print(name2.strip())
#repalce
name="road to code"
newString=name.replace("o","#")
print(newString)2️⃣Write a program to implement escape character to use single quote and double quote in the same string.
👁 Show Answer
sentence="I\'m Good .She said , How Are You ?"
print(sentence) #Escape Character
