
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,
- Comments in Python Programming
- tkinter - Hello World! Program
- How to install Python 3.11 on Mac
- Python matplotlib segmentation fault: 11 macOS Big Sur
- Change label (text) color in tkinter
- Python Hello World! Program with code example (snippet)
- Calculate discount amount python code
- Take input argument from command line in Python Programming
- How to pip install Python Modules in VSCode
- Tkinter - add x and y padding to label text
- Python raise error with message example
- Check if String Contains a Substring - Python
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- What does b prefix before a String mean in Python?
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to List all Packages installed using pip [Python]
- Convert Float to String in Python
- Change the background of Tkinter label or text
- How to Install Python Modules in VS Code
- Indent Python code in Notepad++
- Validate email address in Python using regular expression (regex)
- Python: Fix command not found pip or pip3 on zsh shell
- TypeError: must be str, not int [Fix Python]
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python - Convert float to String
More Posts:
- Ubuntu zsh: command not found: nano - zsh
- Create Duplicate Line Visual Studio Code (above or below) Example - HowTos
- [Solved] SharePoint Search Internal server error exception - SharePoint
- Android : Class file collision: A resource exists with a different case - Android
- Get the Size of HTTP Response using cURL Command (Content Length) - cURL
- Android Activity Main xml stuck loading - Android-Studio
- Install Docker Desktop on M1/M2 Apple Silicon ARM Chip Mac - Docker
- Go to Line Number option in Windows Notepad - NotepadPlusPlus