Introduction to Python Programming – A
Beginner’s Guide
What is Python?
Python is a high-level, interpreted programming language created by Guido van Rossum in 1991. It
emphasizes readability, simplicity, and has a wide range of applications including web
development, data analysis, artificial intelligence, automation, and more.
Basic Syntax
Python uses indentation instead of braces. Variables do not need explicit declaration. Example:
x = 5
print('Hello, Python!')
Data Types
Common data types include int, float, str, list, tuple, set, and dict.
Example:
name = 'Alice'
age = 20
pi = 3.14
numbers = [1, 2, 3]
Control Flow
Python supports if-else statements and loops:
for i in range(5):
print(i)
if age >= 18:
print('Adult')
else:
print('Minor')
Functions
Functions are defined using the def keyword:
def greet(name):
return 'Hello, ' + name
print(greet('Alice'))
Common Programs
Factorial:
def factorial(n):
return 1 if n==0 else n*factorial(n-1)
Palindrome Check:
def is_palindrome(s):
return s == s[::-1]
Prime Check:
def is_prime(n):
if n<2: return False
for i in range(2, int(n**0.5)+1):
if n%i==0:
return False
return True
Conclusion
Python is beginner-friendly, versatile, and widely used in modern industries. Learning Python builds
a strong foundation for programming and problem-solving.