Use of String in Python Programming
Author: Al-mamun Sarkar
Date: 2020-03-24 19:57:12
The string is a message or a sentence or a paragraph. A string in Python has to be surrounded by a single quotation(') or double quotation(").
Print String:
print('Hello')
print('Welcome to artofcse.com')
Output:
Hello
Welcome to artofcse.com
String Variable:
message = "Welcome to ArtOfCSE"
name = 'Jone Doe'
print(message)
print(name)
Output:
Welcome to ArtOfCSE
Jone Doe
Looping a String:
for c in "hello world":
print(c)
Getting String Length:
message = "Hello, World!"
print(len(message))
Checking if a substring is a part of a string:
message = "Welcome to Artofcse"
print("Artofcse" in message)
Checking if a substring is not a part of a string:
message = "Welcome to Artofcse"
print("Artofcse" not in message)
String Concatenation in Python:
first_name = "Jone "
last_name = "Doe"
full_name = first_name + last_name
print(full_name)
Escape Character In Python:
text = "Welcome to \"ArtofCSE\"."
text2 = 'Dhaka is Bangladesh\'s Capital '
message = 'This is first line. \nThis is another line'
print(text)
print(text2)
print(message)