10 Ways To Use Print function In Python (2 Min)
In this tutorial, you'll learn 10 ways to use the print() function in Python.
—
Facebook: https://www.facebook.com/GokceDBsql
—
Video Transcript:
—
Connect MySQL In Python: https://www.youtube.com/watch?v=0qBctY82et0
—
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn 10 Ways to use the print function in Python. Number one, to print a string, use single quotes within parentheses.
Number two, you can also use double quotes instead of single quotes and it's just a matter of preference. Number three, use the backslash character to escape courts within quotes. Number four, the print function accepts zero or more expressions as arguments as long as they are separated by commas.
Here, I'm passing three arguments to the print function and the second argument is a variable of the typed string. Number five uses the percent formatter to format the print output. Alternatively, you can use the format method in conjunction with the curly braces for placeholders to format the print output.
Number seven, you can also use the plus operator to concatenate strings. Note, if you're concatenating a variable that is not of the typed string, you'll have to use the str function to convert it to a string first. Number eight, make use of the triple quotes for a long message that spans multiple lines.
Number nine, leverage the backlash to escape special characters such as the tab space or the new line character. Last but not least, number 10 users before the first quote to print a raw string when you want the special characters to print as is. There you have it.
Make sure you like, subscribe, and turn on the notification bell until next time.
# 1. print a string using single quotes
print('1. Hello World')
# 2. print a string using double quotes
print("2. Hello World")
# 3. use backslash to escape quotes within quotes
print("3a. Hello \"World\"")
print('3b. Hello \'World\'')
# 4. print() functions accepts zero or more expressions as arguments, separated by commas
my_sql_string = "I'm MySQL."
print("4. Hello World,", my_sql_string, "Nice To Meet You!")
# 5. use the % formatter to format the print output
my_sql_name = "MySQL"
my_sql_age = 27
print("5. My name is %s and I'm %d years old." % (my_sql_name, my_sql_age))
# 6. format method
print("6. My name is {} and I'm {} years old.".format(my_sql_name, my_sql_age))
# 7. + operator
print("7. My name is " + my_sql_name + " and I'm " + str(my_sql_age) + " years old.")
# 8. use the triple quotes for a long message that spans multiple lines
print('''8. My name is {}
And I'm {}
years old.
'''.format(my_sql_name, my_sql_age))
# 9. use backslash to escape special characters
print("9a. My name is \tMySQL")
print("9b. My name is \nMySQL")
# 10. use r before the first quote to print raw string
print(r"10. My name is \tMySQL")
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «10 Ways To Use Print function In Python (2 Min)», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.