[go: up one dir, main page]

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

Python Basics With Examples

Uploaded by

mihawkbieber
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)
3 views2 pages

Python Basics With Examples

Uploaded by

mihawkbieber
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 Basics with Examples

Introduction to Python
Python is a high-level, interpreted programming language known for its readability and flexibility. It
is widely used in web development, data science, artificial intelligence, automation, and more.

Hello World Example


A simple Python program looks like this:

print("Hello, World!")

Variables & Data Types


Variables in Python do not need explicit declaration. Common types include int, float, str, and bool.

age = 21
pi = 3.14
name = "Alice"
is_student = True
print(name, age, pi, is_student)

Control Structures
Python uses indentation instead of braces. - if/elif/else for conditions - for/while loops for iteration

x = 10
if x > 5:
print("Greater than 5")
else:
print("5 or less")

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

Functions
Functions are defined using the 'def' keyword.

def greet(name):
return "Hello " + name

print(greet("Alice"))

Lists, Tuples, Sets, Dicts


Python has powerful collection types. - list: ordered, mutable - tuple: ordered, immutable - set:
unordered, unique values - dict: key-value pairs
fruits = ["apple", "banana", "cherry"]
point = (10, 20)
unique = {1, 2, 3}
person = {"name": "Alice", "age": 25}
print(fruits, point, unique, person)

Best Practices
- Use descriptive variable names - Follow PEP 8 (Python style guide) - Write modular code with
functions - Use virtual environments for projects

Tips
- Use list comprehensions for concise loops - Explore Python standard library - Use 'pip' for
package management

Diagram (Textual)
Python Program Flow: Input -> Processing -> Output Example: user input -> calculation -> print
result

Conclusion
Python is beginner-friendly yet powerful. With practice, you can quickly build scripts, apps, and
advanced projects.

You might also like