a step-by-step Python tutorial for beginners. In this tutorial, we'll cover the basics of Python programming, including variables, data types, control structures, functions, and more. Let's get started:
python --version
to verify that Python is installed correctly and check its version..py
extension (e.g., hello.py
).print("Hello, World!")
hello.py
file.python hello.py
and press Enter. You should see the output "Hello, World!" displayed on the screen.Congratulations! You've written your first Python program.
# Integer age = 25 # Floating-point number height = 5.11 # String name = "John Doe" # Boolean is_student = True
type()
function to check the data type of each variable:print(type(age)) print(type(height)) print(type(name)) print(type(is_student))
python filename.py
. You should see the data types of the variables printed on the screen.a = 10 b = 5 # Addition result = a + b print(result) # Subtraction result = a - b print(result) # Multiplication result = a * b print(result) # Division result = a / b print(result) # Modulus (Remainder) result = a % b print(result) # Exponentiation result = a ** b print(result)
x = 10 if x > 5: print("x is greater than 5") else: print("x is not greater than 5")
# Loop through a range of numbers for i in range(5): print(i) # Loop through a list fruits = ["apple", "banana", "orange"] for fruit in fruits: print(fruit)
count = 0 while count < 5: print("Count:", count) count += 1
def greet(name): print(f"Hello, {name}!") greet("Alice")
def add(a, b): return a + b result = add(3, 5) print(result)
input()
function:name = input("Enter your name: ") print(f"Hello, {name}!")
pip
(Python package manager) and import it in your code.# Install the `requests` library using pip # Run this command in your terminal: pip install requests import requests response = requests.get("https://www.example.com") print(response.status_code)