
If you are a student learning Python Programming I am sure that your Teacher gives you a lot of code questions wherein you are asked to take inputs from the user from the command line or the Terminal to solve the problem.
In order to take input argument from the command line, you can make use of the input() function, let's see some examples,
Example 1: Take input from the command line as a name and display a greeting!print ("What's your name?")
name = input()
print(f"Hello {name}! Hope you are doing good!")
Output:
What's your name?
Sam
Hello Sam! Hope you are doing good!
Example 2: Add two numbers by the inputs provided by the user as Terminal arguments
"""
In this example, we will
take a look at how to
get input arguments
from the user using the command line
in Python Programming
Author: Code2care.org
Date: 03-Apr-2022
Version: 1.0
"""
no1 = int(input())
no2 = int(input())
print ("Sum: ",no1+no2)
Output:
10
20
Sum: 30
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- How to Gracefully Close Jupyter Notebook - Python
- Mac turn dark mode on or off using terminal command - MacOS
- Android Development - How to switch between two Activities - Android
- How do I get a list of all branches in Git? - Git
- Python: Access Environment Variables - Python
- Calculate days between dates using dateutils ddiff command - Linux
- auth_client_using_bad_version_title : Error Android Lint - Android
- How to Download Jira App for Mac - Jira