Versatile High-Level Language Widely used in web development , data analysis , AI , and more. Origins Created by Guido van Rossum in 1991.Maintained by the Python Software Foundation. Emphasis on Readability Enables developers to write clean and understandable code. Efficiency Allows expressing concepts in fewer lines of code. OVERVIEW
Key Features
Installing a Python Interpreter Interpreter is needed to execute Python programs Windows Download Python from python.org Comes with IDLE, an Integrated Development Environment suitable for beginners . Linux Most distributions come with Python preinstalled . Check version by typing python3 in the terminal . macOS Typically includes Python 2.7 by default . Download Python 3 from python.org for the latest features and compatibility. Online Interpreters For quick experiments and learning, use online interpreters like GeeksforGeeks IDE .
First Python Program print ( "Hello, Python World!" ) print() is a built-in function , used to display messages or results on the console output
Evolution of Python
Popularity of Python
Prerequisites of Learning Python
Python vs Java Features Python Java Typing Dynamically Typed Statically Typed Syntax Concise, Uses indentation Verbose, uses braces Flexibility Flexible and easy to modify Strict and rigid structure Usage Ideal for scripting and rapid prototyping Ideal for large scale applications
Python vs Java Codes: Python print ("Hello, world!") Java public class HelloWorld { public static void main (String[] args ) { System.out.println ("Hello, world!"); } }
Applications of Python
Organizations using Python
Getting Started Basic Python Code:
Variables in Python Dynamic Typing No need for explicit variable declarations. Type is determined by the value assigned. Naming Conventions Variable names should be descriptive . Use underscores to separate words (e.g., my_variable ). Assignment Use the = operator to assign values. Multiple assignments are possible (e.g., x, y = 5, 10).
Comments in Python Single-line comment use # Multi-line comment use “”” your comment “””
User Input Normal Input: name = input ("Enter your name: ") print( f"Hello , {name}!") Inputs with Conversion: num1 = int ( input ("Enter the first number: ")) num2 = int ( input ("Enter the second number: ")) product = num1 * num2 print( f"The product is: {product}")
Conditional Statements if-else age = 18 if age >= 18: print("You are an adult.") els e: print("You are a minor.")
Functions Functions in Python allow you to encapsulate code for reuse and better organization . ex. def greet(name): print( f"Hello , {name}!") greet("Python")
Loops Loops are used to execute a block of code repeatedly . For Loop for i in range (5): print( i ) # Output: 0, 1, 2, 3, 4
Modules and Libraries Python’s standard library provides a wealth of modules for various tasks . Example: Importing a Module # Using the math module import math result = math.sqrt (25) print(result) # Output: 5.0