Language Switcher

【Python3】How to Create Strings

You can create a string by enclosing text in quotes.

  • You can use ' (single quotes) or " (double quotes).
  • Multi-line strings are enclosed in ''' or """ (triple quotes).
Python
# How to create strings (single-line)
string_a = 'Hello!'
string_b = "Hello World!"

print(string_a)
print(string_b)


'''
Output:

Hello!
Hello World!
'''
Python
# How to create strings (multi-line)
long_string_a = '''
This is
a multi-line
string.
'''

long_string_b = """
This is also
a multi-line
string.
"""

print(long_string_a)
print(long_string_b)


'''
Output:

This is
a multi-line
string.


This is also
a multi-line
string.
'''

コメント

Copied title and URL