In this Python String lesson we want to learn about Create Strings Data Type in Python, because most programs gather some sort of data, and after that they do something useful with that. now first of all what is string ? so string is a series of characters. Anything inside quotes is considered a string in Python.
1 2 |
"Hello World" 'Hello World' |
These are python string, you can create strings in single and double quotes.
Also we can use variables with Strings.
1 2 |
greeting = "How are your" print(greeting) |
You can use functions with strings, for example we are going to make upper and lower the string.
1 2 3 4 |
name = "Geekscoder.com" print(name.upper()) print(name.lower()) |
This is the result.

Also you can use f-string, so F-strings provide a way to embed expressions inside string literals, using a minimal syntax.
1 2 3 4 5 6 7 8 9 10 |
myname = "Parwiz" age = 25 email = "par@gmail.com" website = "geekscoders.com" fulltext = f'My name is {myname}, my age is {age},' \ f' my email is {email} and my website is {website}' print(fulltext) |
F-String was introduced in python 3.6, if you are using python 3.5 than you can use .format.
1 2 3 4 5 6 7 8 9 |
myname = "Parwiz" age = 25 email = "par@gmail.com" website = "geekscoders.com" fulltext = "My name is {}, my age is {}, my email is" \ " {} and my website is {} ".format(myname, age, email, website) print(fulltext) |
You can add newline and tab in the string
1 2 3 4 |
print("Hello") print("\t Hello") print("Geeks \n Coders") |
This is the result.

Also you can concatenate two strings, for example you have two strings and you want to make it one string than you can simply add these two strings.
1 2 3 |
a = "Geeks" b = "Coders" print(a+b) |
Also you can do slicing on python strings, for example in here i want to get the characters from 2 up to 4.
1 2 3 |
a = "GeeksCoders" print(a[2:4]) |