0% found this document useful (0 votes)
2 views2 pages

Python Programming Basics

Uploaded by

magarratna471
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Programming Basics

Uploaded by

magarratna471
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Programming Basics

1. Introduction to Python
- Python is a high-level, interpreted programming language.
- Easy to read and write, supports multiple paradigms: procedural, object-oriented, and functional.

2. Data Types
- Numeric: int, float, complex
x = 10 # int
y = 3.14 # float
z = 1+2j # complex
- String: sequence of characters
name = "Ratna"
print(name[0]) # Output: R
- Boolean: True or False
is_active = True

3. Variables and Input


age = int(input("Enter your age: "))
print("Your age is", age)

4. Conditional Statements
x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

5. Loops
- For Loop:
for i in range(5):
print(i)
- While Loop:
count = 0
while count < 5:
print(count)
count += 1

6. Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Ratna"))

7. Lists and Dictionaries


- List: Ordered collection
fruits = ["apple", "banana", "cherry"]
print(fruits[1]) # Output: banana
- Dictionary: Key-value pairs
student = {"name": "Ratna", "age": 20}
print(student["name"])

8. Simple Example: Calculator


def add(a, b):
return a + b
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
print("Sum:", add(x, y))

9. Conclusion
Python is beginner-friendly, versatile, and widely used in web development, data analysis, AI, and
automation.
Learning the basics lays the foundation for advanced programming.

You might also like