python string literal declaration
There are various ways to declare string literal in python.
I will introduce them one by one in this page.
First way is to use single quotes like 'string'
Second way is to use double quotes like "string"
Last way is to use triple quotes like """hello""" or '''hello'''
or
Every way can declare string literal in python. but there are some differences.
Triple quotes can declare multiple lines. all whitespace that is in triple quotes will be included in the string literal.
Double quotes can include single quote in string and in contrary, single quotes can include double quote in string.
so then, let's check them.
I will introduce them one by one in this page.
First way is to use single quotes like 'string'
1
|
str1 = 'hello'
| cs |
Second way is to use double quotes like "string"
1
|
str1 = "hello"
| cs |
Last way is to use triple quotes like """hello""" or '''hello'''
1
|
str1 = '''hello'''
| cs |
or
1
|
str1 = """hello"""
| cs |
Every way can declare string literal in python. but there are some differences.
Triple quotes can declare multiple lines. all whitespace that is in triple quotes will be included in the string literal.
Double quotes can include single quote in string and in contrary, single quotes can include double quote in string.
so then, let's check them.
1
2
3
4
5
6
7
8
9
|
str1 = "'hello'"
str2 = '"python"'
str3 = '''hello
this is multiple lines
'''
print(str1)
print(str2)
print(str3)
| cs |
Comments
Post a Comment