Skip to content

Latest commit

 

History

History
136 lines (96 loc) · 2.37 KB

basics.md

File metadata and controls

136 lines (96 loc) · 2.37 KB

Python Programming Basics for Experienced Developers

This file provides a concise yet comprehensive overview of Python's fundamental concepts, offering a simplified introduction to the language's key elements, making it an ideal starting point for gaining a solid understanding.

Writing Your First Python Program

  1. Create a new Python file (e.g., hello.py) using a code editor.
  2. Add the following code to print "Hello, World!" to the console:
print("Hello World!!")

Variables and Data Types

Python supports various data types:

# Integer
x = 10

# Float
y = 3.14

# String
name = "Alice"

# Boolean
is_student = True

Basic Operations

Perform arithmetic and logical operations:

# Arithmetic
sum = x + y
difference = x - y
product = x * y
division = x / y
remainder = x % 3

# Logical
and_result = True and False
or_result = True or False
not_result = not True

Conditional Statements

Make decisions with conditional statements:

if x > y:
    print("x is greater than y")
elif x == y:
    print("x is equal to y")
else:
    print("x is less than y")

Loops

Execute code repeatedly using loops:

# For loop
for i in range(5):
    print(i)

# While loop
counter = 0
while counter < 5:
    print(counter)
    counter += 1

Lists and Dictionaries

Explore common data structures:

# List
fruits = ["apple", "banana", "cherry"]

# Dictionary
person = {"name": "John", "age": 30, "is_student": False}

Functions

Create reusable code blocks with functions:

def greet(name):
    print("Hello, " + name + "!")

greet("Alice")

Input and Output

Interact with users using input and output:

user_input = input("Enter your name: ")
print("Hello, " + user_input + "!")

Comments

Document your code using comments:

# This is a single-line comment

"""
This is a
multi-line comment
"""

Exception Handling

Handle errors gracefully using try-except blocks:

try:
  result = x / 0
except ZeroDivisionError:
  print("Error: Division by zero")

Welcome to the world of Python! This guide is designed to help experienced developers quickly grasp the fundamentals of Python programming. Whether you're transitioning from other languages or expanding your skillset, this repository will give you the essential tools to start building with Python.