python define string code example

Example 1: how to create string in python

string = "this is string"
#or
string = 'this is also string'

Example 2: string in python

# ways to dfefine string in python
string = "String"
string = str(string)

# Can Add strings
s1  = "Str"
s2 = "ing"
s = s1 + s2 # "String"

Example 3: {} string python

txt1 = "My name is {fname}, I'm {age}".format(fname = "John", age = 36)
txt2 = "My name is {0}, I'm {1}".format("John",36)
txt3 = "My name is {}, I'm {}".format("John",36)

#https://www.w3schools.com/python/ref_string_format.asp

Example 4: how to create a string in python

var1 = "A String"

Example 5: define a string in python

string1 = "something"
string2 = 'something else'
string3 = """
something
super
long
"""