Advertisement
Functions | Description |
---|---|
print() | This output function, used to generate an output at the console. |
input() | 1) This input function is used to read a line of input entered by the user at the console and returns it as a string. |
print(value, ..., sep = ' ', end = '\n' , file = sys.stdout, flush = False)
Parameters | Description | value | This is a single object value passed to the print() function, which will be printed. |
... | The three dots ... signifies that we can even pass multiple objects(separated by commas) to the print() function. |
---|---|
sep | This is a separator used to separate the objects passed to the print() function. Default value of sep is ' ' i.e. a space. |
end | The value of end parameteris printed at the last i.e. after all the objects passed to print() function, are printed. Default value of end is '\n' i.e. a newline character. |
file | If the value of file is specified then the print() function can be used to print the objects in the file, otherwise, by default sys.stdout prints the objects on the console. |
flush | The flush can only be given a bool value. By default, the value of flush is False, if True the output stream is flushed. |
Advertisement
# Python - The print() function
i = 10
f = 10.8
d = 19.7907
str1 = 'Hello'
# Passing a single object to be printed to the print() function
print('Hello World!')
# Passing multiple objects to be printed to the print() function
print(i, f, d, str1)
# Passing multiple objects to be printed to the print() function
# And, also passing it arguments to alter with its default behaviour
print(i, f, d, str1, sep='|', end='End')
Hello World!
10 10.8 19.7907 Hello
10|10.8|19.7907|HelloEnd
# Python - The print() function
i = 10
f = 10.8
d = 19.7907
str1 = 'Hello'
# Opening the file using open() method of file object
file1 = open('File1.txt','w')
# Calling the print() function with file object
# To make it write to the file and not the default sys.stdout i.e. console
print(i, f, d, str1, file=file1, flush=True)
# Closing the file after writing data to it.
file1.close()
10 10.8 19.7907 Hello
input(prompt=None)
# Python - The raw_input() function
# Calling the input() function by passing a string to it, as a prompt to the user
str1 = input('What is your favorite season? : ' )
print('Your answer is : ', str1)
# Calling the input() function by not passing anything as a prompt to the user
# i.e. A blank prompt
str2 = input()
print(str2)
What is your favorite season? : Autumn
Your answer is : Autumn
Never give up!
Never give up!
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement