پایتون

Welcome!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

6

پرینت متن و متغیر در کنار هم

سلام . من میخوام  متن و متغیر را در کنار هم چاپ کنم . با چه روش هایی میتونم این کار را انجام بدم؟

آواتار
انصراف
1 پاسخ
2
بهترین پاسخ

به پنج روش میشه این کار را انجام داد

مثال:

a = 'viraweb'
b = 123

روش اول:

print('I work in %d %s' % (a, b))

روش دوم:

print('I work', a, b)

روش سوم:

print('I work {} {}'.format(a, b))

روش چهارم:

print('I work ' + str(a) + ' ' + b)

روش پنجم:

print(f'I work {a} {b}')

خروجی چاپ شده:

I work viraweb123

آواتار
انصراف