Input - Output
Input - output in python
In this Article we will work with some built-in functions which are print(
) and input ( )
But first understand what basically a function is .
A function is defined as a set of code which is dedicated to some task.
> you can easily identify a function by parenthesis " ( )
" .
each function name in most of
programming languages ends with ( ).
Now lets move to our topic .
How to use print( ) ?
as the name suggest the print( ) function is used to print data or some
value on the console screen .
Syntax :
print( data [,sep = ' ' ][,end = ' \n' ])
Note : All the things written inside the
parenthesis are called as arguments and the things under [ ] can be ignored
these are optional .
the print() function can accept one or more data arguments.
>>> print(20)
20
>>> print("hello world")
hello world
>>>
The above code example shows how
can you print data using print function .
Now lets see how can we print variable data .
>>> var = "Dynamic Coding"
>>> print(var)
Dynamic Coding
>>>
Lets print string and variable data at a same time .
>>> var = "Dynamic Coding"
>>> print("Welcome to ",var)
Welcome to Dynamic Coding
>>>
Note : There are many ways to print variable and string data together and we will
discuss them in a separate blog .
Working with sep and end arguments .
* The print() function provides a sep argument that can change the character that's used for separating strings from one space to something else .
>>> print(1,2,3,4,5,6,sep = ':')
1:2:3:4:5:6
The above code example uses the sep argument to separate the integers with
semicolon ' : ' .
* The print( ) function also provides an end argument that can change the
ending character for a print() function from a new line character (\n ) to
something else .
Note : By default the end argument has a \n value which is known as new line escape sequence for new line .
>>> print("welcome to \n dynamic coding")
welcome to
dynamic coding
>>>
The above code shows the use of \n .
>>> print(1,2,3,4,5,6,end='????')
1 2 3 4 5 6????
The Above code uses the end argument to put some questions marks at the end
of the data.
Note : if necessary , you can code both sep
and end argument in the same function call.
name = input("Enter Your Name: ")
print("nice to meet you ",name)
Enter Your Name: Alex
nice to meet you Alex
num = input("Enter a integer ")
print('you entered ',num)
print('of data type ',type(num))
Enter a integer 123
you entered 123
of data type <class 'str'>
No comments