Topic 1:- 2 steps of Introduction and Setup of Python

image 2

Play Store Application link – Java to Python in 17 Steps – App on Google Play

Github Project lInk – https://github.com/kuldeep101990/Python_step1

1. Introduction

What is Python?

Python is a high-level, interpreted programming language known for its simplicity and readability. Unlike Java, Python focuses on reducing boilerplate code, allowing you to write less and achieve more. It is widely used in fields like web development, data science, artificial intelligence, and scripting.


Differences Between Python and Java

FeaturePythonJava
Syntax SimplicityVery simple and concise (no semicolons, no braces)Verbose (requires explicit syntax rules)
TypingDynamically typedStatically typed
CompilationInterpreted (runs line by line)Compiled (converted to bytecode first)
LibrariesExtensive built-in librariesRequires external libraries for many tasks
Code StructureIndentation-basedCurly-brace-based

Python as a Dynamically Typed Language

In Java, you define variable types explicitly:

int number = 10;
String name = "John";

In Python, the type is determined at runtime:

number = 10  # Integer
name = "John"  # String

This makes Python more flexible but also requires careful handling to avoid runtime errors.


Setting up Python

  1. Download Python:Python.org
    • Install Python 3.x (latest stable version).
  2. Install an IDE:
    • Use VS Code or PyCharm.
    • VS Code is lightweight, open-source, free, and easy to configure, making it an excellent choice for Python development. For this tutorial, we will use VS Code.

Setting up VS Code for Python Development

  1. Install VS Code:
  2. Install the Python Extension:
    • Open VS Code.
    • Go to the Extensions view by clicking on the square icon on the left sidebar or pressing Ctrl+Shift+X.
    • Search for “Python” and install the official extension by Microsoft.
  3. Verify Python Installation:
    • Open the terminal in VS Code (use `Ctrl+“).
    • Type python --version to ensure Python is installed and recognized.
  4. Set up a Python Workspace:
    • Create a new folder for your Python projects.
    • Open this folder in VS Code by clicking File > Open Folder.
    • Create a new Python file (e.g., main.py) and start coding.
  5. Configure Python Interpreter:
    • Press Ctrl+Shift+P to open the Command Palette.
    • Search for “Python: Select Interpreter” and select the Python version installed on your system.

First Python Program vs. First Java Program

Java Code:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Python Code:

print("Hello, World!")

  • No class or main() function is required in Python.
  • You simply write the functionality directly, which makes scripting faster and easier.

Real-World Scenario: Greeting Application

Imagine you’re building an app to greet users based on their names. Let’s compare how it’s done in Java and Python:

Java Implementation:

import java.util.Scanner;
public class GreetingApp {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter your name: ");
        String name = scanner.nextLine();
        System.out.println("Hello, " + name + "!");
        scanner.close();
    }
}

Python Implementation:

name = input("Enter your name: ")
print(f"Hello, {name}!")

  • Python’s input() simplifies reading user input.
  • String interpolation (f"{name}") replaces Java’s + for string concatenation.

Complete Python Program

Here’s a complete Python program that showcases everything discussed:

# A simple Python program for Java developers
# Function to greet a user
def greet_user():
    name = input("Enter your name: ")  # Taking user input
    print(f"Hello, {name}! Welcome to Python.")
# Main function
if __name__ == "__main__":
    print("Welcome to the Python tutorial for Java developers!")
    greet_user()

How to Run:

  1. Copy and paste the code into a file named greeting_app.py.
  2. Run it using the terminal: python greeting_app.py

Output example:

Welcome to the Python tutorial for Java developers!
Enter your name: Deep
Hello, Deep! Welcome to Python.


This simple start demonstrates Python’s power and elegance. Stay tuned for the next tutorial where we’ll dive deeper into Python’s control structures!

Leave a Reply

Your email address will not be published. Required fields are marked *