You are currently viewing this course as Guest.
Python – Strings
Python strings are written in single or double quotes.
The following code shows basic Python string operations as well as string slice methods.
str = 'Hello World!'
print (str) # Prints complete string
print (str) # Prints first character of the string
print (str[2:5]) # Prints characters starting from 3rd to 5th
print (str[2:]) # Prints string starting from 3rd character
print (str * 2) # Prints string two times
print (str + "TEST") # Prints concatenated string
The output of the code is as below,
Hello World!Hello World!