Intorduction | Python Tutorial - Learn with VOKS
Next

Intorduction


Python is a high-level, easy-to-read programming language created by Guido van Rossum in 1991.

It is used for:

  • ๐ŸŒ Web development
  • ๐Ÿ“Š Data analysis
  • ๐Ÿค– Artificial Intelligence & Machine Learning
  • ๐ŸŽฎ Game development
  • ๐Ÿ–ฅ๏ธ Automation & scripting
  • ๐Ÿ“ฑ App development

Python is popular because:

  • It has simple syntax (easy to read like English)
  • It has a large community
  • It works on Windows, Mac, and Linux
  • It has thousands of ready-made libraries

Installing Python

To start coding:

  1. Go to the official website:
  2. ๐Ÿ‘‰ Python Software Foundation
  3. Download Python for your operating system.
  4. Install it.
  5. During installation, check โœ… "Add Python to PATH".

After installing, open Command Prompt (Windows) or Terminal (Mac/Linux) and type:

python --version

If installed correctly, it will show something like:

Python 3.12.1

Writing Your First Python Program

The traditional first program is "Hello, World!"

print("Hello, World!")

Explanation:

  • print() โ†’ Displays output on the screen
  • "Hello, World!" โ†’ Text (called a string)

Python Syntax Basics

Python is indentation-based (spaces matter!).

Example:

if 5 > 2:
    print("Five is greater than two")

Notice the space before print() โ€” that indentation is required.

Variables in Python

Variables store data.

name = "Alice"
age = 25
height = 5.6
is_student = True

Variable Rules:

  • No spaces in variable names
  • Cannot start with a number
  • Case-sensitive (age โ‰  Age)

Data Types in Python

Here are the main data types:

| Data Type | Example | Description |
|-----------|----------|------------|
| int | 10 | Whole numbers |
| float | 3.14 | Decimal numbers |
| str | "Hello" | Text |
| bool | True / False | Boolean values |
| list | [1, 2, 3] | Collection (changeable) |
| tuple | (1, 2, 3) | Collection (unchangeable) |
| dict | {"name": "Alice"} | Key-value pairs |

Example:

x = 10              # int
y = 3.14            # float
name = "John"       # string
is_valid = False    # boolean

Taking User Input

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

โš ๏ธ Important: input() always returns a string.

If you want a number:

age = int(input("Enter your age: "))
print("You are", age, "years old.")

Operators in Python

| Type | Operators | Example |
|------|-----------|----------|
| Arithmetic | + - * / % | 5 + 2 |
| Comparison | == != > < >= <= | 5 > 3 |
| Logical | and or not | x > 5 and x < 10 |

Example:

a = 10
b = 5

print(a + b)
print(a > b)

Conditional Statements (if-else)

Used for decision making.

age = 18

if age >= 18:
    print("You are an adult")
else:
    print("You are a minor")

With elif:

score = 85

if score >= 90:
    print("Grade A")
elif score >= 80:
    print("Grade B")
else:
    print("Grade C")

Loops in Python

1. For Loop

for i in range(5):
    print(i)

Output:

0
1
2
3
4

2. While Loop

count = 0

while count < 5:
    print(count)
    count += 1

Functions in Python

Functions let you reuse code.

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

greet("Alice")

Function with return value:

def add(a, b):
    return a + b

result = add(5, 3)
print(result)

Lists in Python

Lists store multiple values.

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

print(fruits[0])       # Access first item
fruits.append("orange")  # Add item
print(len(fruits))     # Length

Dictionaries in Python

Dictionaries store key-value pairs.

student = {
    "name": "John",
    "age": 20,
    "course": "Computer Science"
}

print(student["name"])

Python Libraries

One of Pythonโ€™s biggest strengths is its libraries.

Examples:

  • math โ†’ Mathematics
  • random โ†’ Random numbers
  • datetime โ†’ Dates & time

Example:

import random

print(random.randint(1, 10))

Comments in Python

Comments are ignored by Python.

# This is a comment

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

Why Learn Python?

Python is used by major companies like:

  • Google
  • Netflix
  • Instagram
  • Spotify

It is also heavily used in:

  • Data Science
  • Machine Learning
  • Automation
  • Web Development
Example Code:
# Hello World
print("Hello, World!")

# If statement example
if 5 > 2:
    print("Five is greater than two")

# Variables
name = "Alice"
age = 25
height = 5.6
is_student = True

# Data types examples
x = 10
y = 3.14
name = "John"
is_valid = False

# Input example
# name = input("Enter your name: ")
# print("Hello", name)

# age = int(input("Enter your age: "))
# print("You are", age, "years old.")

# Operators
a = 10
b = 5
print(a + b)
print(a > b)

# Conditional statements
age = 18
if age >= 18:
    print("You are an adult")
else:
    print("You are a minor")

score = 85
if score >= 90:
    print("Grade A")
elif score >= 80:
    print("Grade B")
else:
    print("Grade C")

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

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

# Functions
def greet(name):
    print("Hello", name)

greet("Alice")

def add(a, b):
    return a + b

result = add(5, 3)
print(result)

# Lists
fruits = ["apple", "banana", "cherry"]
print(fruits[0])
fruits.append("orange")
print(len(fruits))

# Dictionary
student = {
    "name": "John",
    "age": 20,
    "course": "Computer Science"
}
print(student["name"])

# Library example
import random
print(random.randint(1, 10))

# Comments example
# This is a single-line comment

"""
This is a
multi-line comment
"""
Python
Intorduction Python Syntax Compare to other Programming Languages How to Install Python Print Statement Python Comments Data Structure and Data Type String Operations in Python Simple Input and Output Simple Output Formatting
All Courses
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL