Contoh program : Program Python untuk Membuat String Multiline Panjang

0
(0)

Contoh 1: Menggunakan tanda kutip tiga

my_string = '''The only way to
learn to program is
by writing code.'''

print(my_string)

Keluaran

The only way to
learn to program is
by writing code.

Kamu bisa memakai '''(multiline string)''' atau """(multiline string)""".


Contoh 2: Menggunakan tanda kurung dan tanda kutip tunggal / ganda

my_string = ("The only way to n"
        	"learn to program is n"
        	"by writing code.")

print(my_string)

Keluaran

The only way to
learn to program is
by writing code.

Jika Anda menggunakan (" ") sintaks, Anda perlu menentukan baris baru secara eksplisit menggunakan n.


Contoh 3: Menggunakan

my_string = "The only way to n" 
        	"learn to program is n" 
        	"by writing code."

print(my_string)

Keluaran

The only way to
learn to program is
by writing code.

Kamu bisa memakai seperti pada contoh kode di atas untuk menulis string multiline.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.