Python - Print
print() is the most important function in Python (actually the most important function in any language). There is nothing to explain specifically. Just follow through following examples.
NOTE 1 : All the examples in this page are written in Python 3.x. It may not work if you use Pyton 2.x
NOTE 2 : All the examples in this page are assumed to be written/run on Windows 7 unless specifically mentioned. You MAY (or may not) need to modify the syntax a little bit if you are running on other operating system.
- Basic Syntax
- Examples
- print("string") - Example 1
- print('string') - Example 2
- print("string1", var1) - Example 3
- print("string1", var1, "string2", var2, ...) - Example 4
- print("string1","\nString2") - Example 5
- print("string",end=' ') - Example 6
Examples :
|
print("Hello World")
Result :-------------------------- Hello World
print('Hello World')
Result :-------------------------- Hello World
score = 75 print("Your score is ",score)
Result :-------------------------- Your score is 75
score = 75 grade = "C"
print("Your score is ",score, " And ", "Your Grade is ",grade)
Result :-------------------------- Your score is 75 And Your Grade is C
score = 75 grade = "C"
print("Your score is ",score, "\nYour Grade is ",grade)
Result :--------------------------
Your score is 75 Your Grade is C
print("===Print without New Line at the end ===") for i in range(5) : print(i, " ")
print("===Print without New Line at the end ===") for i in range(5) : print(i, " ", end=' ')
Result :--------------------------
===Print without New Line at the end === 0 1 2 3 4 ===Print without New Line at the end === 0 1 2 3 4
< Example 7 >
|