What is Python
Python is a high-level, interpreted programming language known for its simplicity and readability. It was created by Guido van Rossum and first released in 1991. Python is widely used for web development, data analysis, artificial intelligence, scientific computing, and automation due to its versatile nature and vast library support.
Python language is being used by almost all tech-giant companies like – Google, Amazon, Facebook, Instagram, Dropbox, Uber… etc.
Python emphasizes code readability with its clear and straightforward syntax, making it a great choice for beginners. Here’s a simple example to get started:
0 1 2 3 4 5 6 7 8 9 |
# This is a comment in Python. # Comments are ignored by the interpreter. # Let's print a message to the console print("Hello, World!") # This will output: Hello, World! |
Explanation
- Comments: Lines starting with
#
are comments. Comments are ignored by the Python interpreter and are used to explain the code. - print() function: The
print()
function outputs the specified message to the console.
Now, let’s see a simple example of a Python program that adds two numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# This program adds two numbers provided by the user # Input function to get user input num1 = input("Enter first number: ") # Example input: 5 num2 = input("Enter second number: ") # Example input: 3 # Convert input strings to integers num1 = int(num1) num2 = int(num2) # Add the two numbers sum = num1 + num2 # Print the result print("The sum is:", sum) # This will output: The sum is: 8 |
Explanation
- input() function: The
input()
function takes user input as a string. - int() function: The
int()
function converts a string to an integer. - Variables:
num1
andnum2
store the input values, andsum
stores the result of adding these two numbers. - print() function: Outputs the result to the console.
ASCII Art Visualization
Here’s a simple ASCII art visualization of how Python executes the addition program:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
User Input +-------+ +-------+ | num1 | ----> 5 | num2 | +-------+ +-------+ | | v v +-------+ +-------+ | int() | | int() | +-------+ +-------+ | | v v +-------+ +-------+ | num1 | | num2 | +-------+ +-------+ | | +--------+ +------+ | | v v +---------+ | sum | +---------+ | v +-------------+ | print() | +-------------+ | v "The sum is: 8" |