Welcome
So today here you are going to learn how to take input from user in python.
Developers often have a need to interact with users, either to get data or to provide some sort of result. Nowadays mostly programs use a dialog box as a way of taking input from users. While Python provides us with an inbuilt function to read the input from the keyboard.
Note: Here we are talking about methods used in python 3.x
Comments
Note: Single line comments and In-Line comments are the same as when we write a comment in continuation of a line of code then it is called In-Line comment. In the above example, the comment written after the print() function is an In-Line comment.
2. Multi-Line Comments: Python multiline comments are enclosed in either triple single quotes (''') or in triple-double quotes ("""). These are helpful when comment does not fit in one line; therefore needs to span across lines. You can see the example in the below code.
Example:
3. Docstring Comments: Docstring is an In-built feature of Python, which is used to associate documentation that has been written with python modules, functions, classes and methods. In Python, the docstring is made available via the __doc__ attribute.
Example:
Taking input in Python |
Taking input in Python
Developers often have a need to interact with users, either to get data or to provide some sort of result. Nowadays mostly programs use a dialog box as a way of taking input from users. While Python provides us with an inbuilt function to read the input from the keyboard.
Note: Here we are talking about methods used in python 3.x
input(): This function is used to take input from the users in python 3.x. When input() function executes program flow will be stopped until the user has given input.
The important thing which you have to keep in mind is, Whatever you enter as input, input() function convert it into a string. Even if you enter an integer value still input() function converts it into a string. You need to explicitly convert it into an integer in your code using typecasting.
Run the program below and try it yourself.
Run the program below and try it yourself.
Comments
Programmers often make use of the comments system, as without the use of it a program could be really confusing and thus consume more time. Comments are useful information that programmers provide to make the reader understand the code. it explains the logic or part used in the code.
There are three types of comments in Python:
1. Single Line Comment: Python Single Line comments are made by using a hashtag (#) symbol with no white spaces and lasts till the end of the line. If comment exceeds one line the put another hashtag on the next line and continue writing the code. You can see the example in the below code.
Example:
There are three types of comments in Python:
1. Single Line Comment: Python Single Line comments are made by using a hashtag (#) symbol with no white spaces and lasts till the end of the line. If comment exceeds one line the put another hashtag on the next line and continue writing the code. You can see the example in the below code.
Example:
Note: Single line comments and In-Line comments are the same as when we write a comment in continuation of a line of code then it is called In-Line comment. In the above example, the comment written after the print() function is an In-Line comment.
2. Multi-Line Comments: Python multiline comments are enclosed in either triple single quotes (''') or in triple-double quotes ("""). These are helpful when comment does not fit in one line; therefore needs to span across lines. You can see the example in the below code.
Example:
3. Docstring Comments: Docstring is an In-built feature of Python, which is used to associate documentation that has been written with python modules, functions, classes and methods. In Python, the docstring is made available via the __doc__ attribute.
Example:
Comments
Post a Comment